1.
Executing Python from the Command Line
To execute Python from the command line, use the command python or python3 followed by the file
name. For example:
python3 script.py
Output:
Hello, World!
2. Tuples in Python
A tuple is an immutable, ordered collection of elements. Tuples are written with parentheses () and
can hold different data types.
my_tuple = (1, 'apple', 3.14)
print(my_tuple)
Output:
(1, 'apple', 3.14)
3. Lambda in Python
A lambda function is an anonymous, small function defined with the lambda keyword. It can have
any number of arguments but only one expression.
add = lambda x, y: x + y
print(add(5, 3))
Output:
4. Creating Classes in Python
A class is a blueprint for creating objects. Define a class using the class keyword followed by the
class name.
class MyClass:
def greet(self):
return "Hello, World!"
obj = MyClass()
print(obj.greet())
Output:
Hello, World!
5. Relational and Logical Operators
Relational operators: Compare values (==, !=, >, <, >=, <=).
Logical operators: Combine conditional statements (and, or, not).
x, y = 5, 10
print(x > y and x != y) # False
print(x < y or x == y) # True
Output:
False
True