Python Tutorial for Beginners #2 - Variables & Data Types (str, int, float, bool)
Video: Python Tutorial for Beginners #2 - Variables & Data Types (str, int, float, bool) by Taught by Celeste AI - AI Coding Coach
Watch full page →Python Tutorial for Beginners #2 - Variables & Data Types (str, int, float, bool)
In this lesson, you’ll learn how to create variables and understand Python’s four basic data types: string, integer, float, and boolean. We’ll also explore the dynamic typing feature of Python and how to use the type() function to check variable types, along with the special None value.
Code
# Creating variables with different data types
name = "Alice" # str: text data
age = 25 # int: whole number
height = 5.6 # float: decimal number
is_student = True # bool: True or False
# Check types using the type() function
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
print(type(height)) # <class 'float'>
print(type(is_student))# <class 'bool'>
# Dynamic typing: variables can change type
x = 10 # x is an int
print(type(x)) # <class 'int'>
x = "hello" # now x is a str
print(type(x)) # <class 'str'>
# None value represents absence of a value
result = None
print(result is None) # True, checks if result is None
Key Points
- Variables store values and are created by assigning with the equal sign.
- Python’s basic data types include
str(string),int(integer),float(decimal), andbool(boolean). - The
type()function reveals the data type of any variable. - Python uses dynamic typing, so a variable’s type can change during execution.
Noneis a special value used to indicate the absence of a value.