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
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying this summary from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Perfectscorer. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for R248,62. You're not tied to anything after your purchase.