livepython.net
CHAPTER 05Working With Data Types
5.5  PRACTICE

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 writeIt does
"Live" + "Python"joins strings: LivePython
"Ha" * 3repeats 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 ** 2floor divide 3, remainder 1, power 49
(2 + 3) * 4brackets first, then **, then * /, then + -
score += 5short for score = score + 5
round(3.14159, 2)rounds to 2 decimals: 3.14
==, !=, >, <, >=, <=compare, answer True or False
= vs === stores, == asks
Noneno 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

  1. 35.Python Program to Join a First and Last NameEasySolve
  2. 36.Python Program to Count the Characters in a WordEasySolve
  3. 23.Python Program to Calculate and Format a Total CostMediumSolve

Numbers

  1. 37.Python Program to Find the Quotient and RemainderEasySolve
  2. 38.Python Program to Calculate Simple InterestMediumSolve
  3. 39.Python Program to Convert Minutes to Hours and MinutesMediumSolve

Booleans and comparisons

  1. 40.Python Program to Compare Two NumbersEasySolve
  2. 41.Python Program to Check If Two Passwords MatchEasySolve

None and type conversion

  1. 42.Python Program to Add Two Numbers Stored as TextEasySolve
  2. 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.