Python Data Types Practice Questions for Beginners
Chapter 5 Recap and Practice
You now know the four basic types inside out, and how to move between them. Here is the chapter in one table:
| You write | It does |
|---|---|
"Live" + "Python" | joins strings: LivePython |
"Ha" * 3 | repeats a string: HaHaHa |
len("Sunny") | counts characters, spaces too: 5 |
f"{name} is {age}" | puts values inside text; {price:.2f} shows 2 decimals |
7 // 2, 7 % 2, 7 ** 2 | floor divide 3, remainder 1, power 49 |
(2 + 3) * 4 | brackets first, then **, then * /, then + - |
score += 5 | short for score = score + 5 |
round(3.14159, 2) | rounds to 2 decimals: 3.14 |
==, !=, >, <, >=, <= | compare, answer True or False |
= vs == | = stores, == asks |
None | no value yet (not 0, not "") |
int(), float(), str() | convert: text to number, number to text |
int(9.7) | cuts off the decimals: 9 |
Practice questions
Use variables and the right type in each program. Where the answer is a calculation, let Python calculate it.
Strings
- 35.Python Program to Join a First and Last NameEasySolve
- 36.Python Program to Count the Characters in a WordEasySolve
- 23.Python Program to Calculate and Format a Total CostMediumSolve
Numbers
- 37.Python Program to Find the Quotient and RemainderEasySolve
- 38.Python Program to Calculate Simple InterestMediumSolve
- 39.Python Program to Convert Minutes to Hours and MinutesMediumSolve
Booleans and comparisons
- 40.Python Program to Compare Two NumbersEasySolve
- 41.Python Program to Check If Two Passwords MatchEasySolve
None and type conversion
- 42.Python Program to Add Two Numbers Stored as TextEasySolve
- 43.Python Program to Print a Temperature ReportHardSolve
Every value has a type, and now you can use, compare and convert all of them. Next: comments, to explain your code.