Python Variables and Data Types
Techverse by Vijay
Coding Tutorial
Python Variables and Data Types
Variables are used to store data, and Python supports several data types such as integers, floats, strings, and booleans. Understanding these is essential for any Python programmer.
1. Variables
Variables store data for later use:
name = "Vijay" age = 20 is_student = True
Here, name is a string, age is an integer, and is_student is a boolean.
2. Common Data Types
- int: Whole numbers. Example:
age = 20 - float: Decimal numbers. Example:
height = 5.9 - str: Text. Example:
name = "Vijay" - bool: True or False. Example:
is_student = True
3. Type Checking
You can check a variable’s type using type():
print(type(age)) # <class 'int'> print(type(height)) # <class 'float'> print(type(name)) # <class 'str'> print(type(is_student))# <class 'bool'>
Conclusion
Understanding variables and data types is the foundation of Python programming. Next, you’ll learn how to make decisions using conditional statements.
Comments
Post a Comment