Question

What is the output? from collections import namedtuple Student = namedtuple('Student' , ['name','age','rollNo']) student1 = Student('Hayden'...

What is the output?

from collections import namedtuple

Student = namedtuple('Student' , ['name','age','rollNo'])

student1 = Student('Hayden' , 26, 6)

print
print ("Name:", student1.name)
print

print ("Age:", student1.age)
print

print ("Roll Number:", student1.rollNo)
print

Group of answer choices

Name: Hayden Age: 26 Roll Number: 6

Hayden 26 6

6 Hayden 26

Age: 6 Roll Number: Hayden Name: 26

Homework Answers

Answer #1

Ans:-

Output of the above program is:- Name: Hayden Age: 26 Roll Number: 6

Explaination:-

The above program is a python program which is implementing namedtuple class from collection. Namedtuple is like a dictionary which contains key and value. The values can be accessed using index or attribute or getattr() method.

In the above program we are using attribute to access the elements.Now, let us go through the lines of code

from collections import namedtuple # this will import the namedtuple from collections in the program

Student = namedtuple('Student' , ['name','age','rollNo']) # this will create student namedtuple where name, age and rollNo are attribute

student1 = Student('Hayden' , 26, 6) # this will add a new student

print
print ("Name:", student1.name) # this method print the name of student using name attribute
print

print ("Age:", student1.age) # this method print the age of student using age attribute
print

print ("Roll Number:", student1.rollNo) # this method print the roll no of student using rollNo attribute
print

So, in the above code, only three statements will be printed and this will be the output of the program, first is name of student using name attribute, second is age of student using age attribute and third is roll number of student using rollNo attribute. Hence, the output will be  Name: Hayden Age: 26 Roll Number: 6

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What is the output from the following code? struct   StudentType{ long id; string name; int age;...
What is the output from the following code? struct   StudentType{ long id; string name; int age; } StudentType stud1; stud1.id = 12345; stud1.name = “Josh”; stud1.age =20; StudentType* ptr = & stud1; ptr->age++; ptr->name = “John”; cout<<stud1.name<<” “ <<stud1.age;
Python Q2) Create a Student class and initialize it with name and roll number. Make methods...
Python Q2) Create a Student class and initialize it with name and roll number. Make methods to : Display - It should display all informations of the student. setAge - It should assign age to student setMarks - It should assign marks to the student.
A university database contains the following information about each student – their full name, their student...
A university database contains the following information about each student – their full name, their student ID number (a randomly assigned 8-digit number), their date of birthday, their sex, their age and the year they joined the university. Identify which data-type each attribute belongs to, and explain your answer.
Use the following data to determine the values of the following questions. Age 23 37 26...
Use the following data to determine the values of the following questions. Age 23 37 26 32 42 31 41 Cholesterol 140 177 155 195 160 144 210 1 What is the dependent variable? Group of answer choices -Age -No answer text provided. -Cholesterol -No answer text provided. 2 What is the independent variable? Group of answer choices -No answer text provided. -Age -No answer text provided. -Cholesterol 3 What is the Y - intercept? Group of answer choices -1517.755...
Question 6:Roger, age 19, is a full-time graduate student at State College. During 2018, he received...
Question 6:Roger, age 19, is a full-time graduate student at State College. During 2018, he received the following payments. What is his taxable income: State scholarship for ten months (tuition and books) $3,600 Loan from college financial aid office 1,500 Cash support from parents 3,000 Cash prize awarded in contest 500 $8,600 Group of answer choices $8,600 $500 $2,900 $4,100 ******************************************************************* Question 8: Early in the year, Mike was in an automobile accident during the course of his employment. As...
Below is output from an ANOVA on “Age” and the number of children living in the...
Below is output from an ANOVA on “Age” and the number of children living in the home (“ChildrenInHome”). Describe what this output is telling us about the relationship “between groups”. ANOVA ChildrenInHome Sum of Squares df Mean Square F Sig. Between Groups 158.082 47 3.363 4.182 .000 Within Groups 189.816 236 .804
When we type in the name of a batch file in Command Prompt, Command Prompt will...
When we type in the name of a batch file in Command Prompt, Command Prompt will look for variables called: Group of answer choices Preset Variables Replacement Variables Permanent Variables Batch Variables We can use this character to pass the output from one command to the next: Group of answer choices | (Pipe) , (Comma) > (Angled Bracket) & (Ampersand) The following is utility tool we can use that are resided in the directory C:\Windows\System32: Group of answer choices IPCONFIG...
1. In C++, programmers can use a class to create a large number of instance variables...
1. In C++, programmers can use a class to create a large number of instance variables of the class's type. Group of answer choices True False 2. When a C++ programmer declares a function, they are required to state all of the following except Group of answer choices {} The type of data, if any, returned by the function The function name The type of data, if any, sent to the function 3. When a C++ programmer calls a function,...
Lab 6: Chemical Formula of Magnesium Oxide A student took a crucible and lid from the...
Lab 6: Chemical Formula of Magnesium Oxide A student took a crucible and lid from the drawer, added 0.257 grams of magnesium metal to it, and heated it until completely ashen. She found the contents had added 0.128 grams of mass. What is the Mass percent for oxygen in the compound after heating? Group of answer choices 66.8% 50% 33.2%
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno,...
Use the following tables to answer Q5 and Q6. Tourist (tno, Name, phone, age,loc) Vehicle (Vno, model, mileage, owner_name, owner_ph)) Rented (tno, Vno) 5. (i)Write an SQL query, to create the table vehicle with following constraints: Vno should begin with second letter ‘v’; Models are one among Thar, X3. Mileage should be above 18 and below 25. No two records can have same phone (ii) Write an SQL query to retrieve the name of the owner who does owns X3...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT