### Python 2.7 Tutorial:

1. Hello World:

 ```python
 # hello.py
 print "Hello, World!"
 ```
 Run it using:
 ```bash
 python hello.py
 ```

2. Variables and Data Types:

 ```python
 # variables.py
 name = "John"
 age = 25
 height = 1.75
 is_student = True
 print "Name:", name
 print "Age:", age
 print "Height:", height
 print "Is Student:", is_student
 ```

3. User Input:

 ```python
 # user_input.py
 name = raw_input("Enter your name: ")
 print "Hello, " + name + "!"
 ```

4. Conditional Statements:

 ```python
 # if_statement.py
 num = input("Enter a number: ")
 if num % 2 == 0:
     print num, "is even."
 else:
     print num, "is odd."
 ```

5. Loops:

 ```python
 # while_loop.py
 count = 0
 while count < 5:
     print "Count:", count
     count += 1
 ```
 ```python
 # for_loop.py
 for i in range(5):
     print "Iteration:", i
 ```

6. Functions:

 ```python
 # functions.py
 def greet(name):
     return "Hello, " + name + "!"
 print greet("Alice")
 ```

7. Lists and Dictionaries:

 ```python
 # lists_and_dicts.py
 my_list = [1, 2, 3, 4, 5]
 my_dict = {'a': 10, 'b': 20, 'c': 30}
 print "List:", my_list
 print "Dictionary:", my_dict
 ```

8. File Handling:

 ```python
 # file_handling.py
 with open("example.txt", "w") as file:
     file.write("Hello, Python 2.7!")
 with open("example.txt", "r") as file:
     content = file.read()
     print "File Content:", content
 ```
We use cookies to personalize and enhance your experience on our site. By using our site, you agree to our use of cookies.
  More information about cookies