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:
variable_name = value
Examples:
name = "Tala" #String age = 22 #Integer height = 5.5 #Float 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:
variable_name = input("Prompt message")
Example:
name = input("Enter your name: ") print("Hello, " + name + "!")
Or
name = input("Enter your name: ") print(f"Hello, {name}!")