Variables and Data Types in Python

📘 Python 👁 67 views 📅 Nov 05, 2025
⏱ Estimated reading time: 1 min

Variables and Data Types in Python

Variables in Python are used to store data. Python automatically detects the data type when a variable is assigned.


1. Variable Rules

  • Must start with a letter or underscore.

  • Can contain letters, digits, and underscores.

  • Cannot be a Python keyword.

  • Python is case-sensitive (age and Age are different).

name = "Alice" _age = 25 number1 = 100

2. Basic Data Types

Data TypeDescriptionExample
intInteger numbersx = 10
floatDecimal numbersy = 3.14
strString (text)name = "Python"
boolBoolean valuesis_valid = True
complexComplex numbersz = 2 + 3j

3. Type Conversion (Casting)

x = 10 # int y = float(x) # convert int to float z = str(x) # convert int to string print(type(x)) # print(type(y)) # print(type(z)) #

4. Multiple Assignment

  • Assign values to multiple variables in one line:

a, b, c = 5, 10, 15 x = y = z = 20

5. Checking Data Type

  • Use type() function to check the data type:

value = 3.14 print(type(value)) #

6. Constants

  • By convention, constants are uppercase:

PI = 3.14159 GRAVITY = 9.8

7. Key Points

  • Variables store data values for later use.

  • Python infers the data type automatically.

  • Basic data types include int, float, str, bool, and complex.

  • Multiple variables can be assigned in one line.

  • Use type() to check the data type.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes