-
What is Python?
- High-level, interpreted programming language
- Simple and easy to learn
- Free and Open-source
- Developed by Guido van Rossum
-
Features Of Python
- Readable and beginner-friendly
- Dynamically Typed
- Cross-platform Compatibility
-
Download Python & Editor/IDE
- Download Python – Official site: python.org
- Choose an Editor/IDE – Options include:
VS Code
PyCharm
IDLE (built-in)
-
Write first Python Program
- print("Hello, World!")
-
Variables In Python
- Used to store data / name given to memory location
- No need to declare data type (Python is dynamically typed)
- Example:
name = "Anshita" # String
age = 30 # Integer
pi = 3.14 # Float
is_active = True # Boolean
-
Rules for Identifiers
- Must start with a letter or underscore (_)
- Can contain letters, numbers, and underscores
- Case-sensitive (Name and name are different)
- Cannot use Python keywords (class, def, etc.)
- Cannot use special characters like $,%,@,!,# etc in identifiers
- It can be of any length
-
Valid Identifiers
- Example:
my_var = 10
_name = "Python"
var123 = 45
-
Invalid Identifiers
- Example:
2var = "Error" # Cannot start with a number
class = 5 # 'class' is a reserved keyword
my-var = 7 # Hyphen (-) is not allowed
-
DataTypes In Python
-
In Python, you can use the type() function to check the data type of a variable.
- Syntax:
type(variableName)
-
Data Types
- Integers
- String
- Float
- Boolean
- None
- Example:
x = 10
y = 3.14
z = "Hello"
a = True
b = None
print(type(x)) # Output: <class 'int'>
print(type(y)) # Output: <class 'float'>
print(type(z)) # Output: <class 'str'>
print(type(a)) # Output: <class 'bool'>
print(type(b)) # Output: <class 'NoneType'>
- Reserved words in Python
- Day 1