Python Basics Test Questions with All Answers
Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name = "Tim"
age = 20
print("%s is %d years old." % (name, age))
For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier. -...
Use two argument specifiers to print that the "name" is an "age" of 20. - Answer-name =
"Tim"
age = 20
print("%s is %d years old." % (name, age))
For list *mylist* of [1, 2, 3], print "A list:" followed by the list, using an argument specifier.
- Answer-mylist = [1, 2, 3]
print("A list: %s" % mylist)
Four basic argument specifiers: - Answer-1. %s - String
2. %d - Integers
3a. %f - Floating point numbers
3b. %.<numberofdigits>f - Floating point numbers with a fixed amount of digits to the
right of the dot.
Print variable astring, "Hello world!", in all lowercase vs. all uppercase - Answer-astring
= "Hello world!"
All lowercase:
print(astring.lower())
All uppercase:
print(astring.upper())
Print a slice of the variable astring, "Hello world!", starting at index 3 and ending at index
6, skipping every other letter (increment of 2) - Answer-astring = "Hello world!"
print(astring[3:7:2])
Print true or false for the variable astring, "Hello world!", checking if it starts with "Hello"
and ends with "asdfghjkl" - Answer-astring = "Hello world!"
print(astring.startswith("Hello"))
print(astring.endswith("asdfghjkl"))
Split the two terms in the variable astring, "Hello world!" - Answer-astring = "Hello
world!"
afewwords = astring.split(" ")
Boolean example with x = 2 and comparisons to 2, 3, and less than 3 - Answer-x = 2
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Perfectscorer. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €12,50. Je zit daarna nergens aan vast.