Python Variables
Variables are used to store data values. In Python, you do not need to declare the type of variable; the interpreter automatically identifies the type based on the value assigned.
Syntax:
x
1
variable_name = value
Examples:
1
1
name = "Tala" #String
2
age = 22 #Integer
3
height = 5.5 #Float
4
is_student = True #Boolean
Python Data Types
Python has several built-in data types. Here are some of the most commonly used ones:
- Numeric Types:
- int: Integer numbers:
age = 22 - float: Floating-point numbers:
height = 5.5
- int: Integer numbers:
- String:
- A sequence of characters enclosed in single, double, or triple quotes:
name = “Tala”
- A sequence of characters enclosed in single, double, or triple quotes:
- Boolean:
- Represents True or False values:
is_student = True
- Represents True or False values:
Python `input`
The input
function allows the user to provide input from the keyboard. The input is always treated as a string.
Syntax:
1
1
variable_name = input("Prompt message")
Example:
1
1
name = input("Enter your name: ")
2
print("Hello, " + name + "!")
Or
1
1
name = input("Enter your name: ")
2
print(f"Hello, {name}!")