Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FOUNDATIONS / CHAPTER 01 / Learn / LESSON 02
Second class. Python stores not only a value but also its type. Four basic types are str for text, int for whole numbers, float for decimal numbers, and bool for True/False.
A string always uses quotes: title = "Health Engine". A whole number has no quotes: visits = 25. A decimal number is also unquoted and uses a dot: height = 1.8. Boolean values are exactly True and False with capital letters.
Quotes change the type. "25" is str, while 25 is int. They may look similar in the console, but only the number can directly take part in arithmetic. You can inspect a value with type(value), although this task only needs correctly typed values and print.
Mini example:
name = "Ada"
lessons = 2
rating = 4.8
online = True
print(name, lessons, rating, online)We do not convert types today. int() and float() arrive in the next lesson, where text data becomes numbers.
Common mistakes: true instead of True, a decimal comma instead of a dot, or quotes around a number meant for arithmetic.
Strings use quotes, int and float are unquoted numbers, and bool is True or False.
AWAITING TYPES
›