0% found this document useful (0 votes)
24 views

Python Syntax List

Please
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Python Syntax List

Please
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Ke Sabhi Syntax Ki List

1. Print Statement:

print("Message")

2. Variables:

variable_name = value

Example: age = 25

3. Conditional Statements:

if condition:

# Code

elif condition:

# Code

else:

# Code

4. Loops:

For Loop:

for variable in iterable:

# Code

While Loop:

while condition:

# Code

5. Functions:

def function_name(parameters):
# Code

return value

6. Classes and Objects:

class ClassName:

def __init__(self, parameters):

# Constructor Code

def method_name(self):

# Code

7. Try-Except Block (Error Handling):

try:

# Code

except Exception as e:

# Handle Exception

finally:

# Code that runs no matter what

8. Importing Modules:

import module_name

from module_name import specific_function

9. File Handling:

with open("file_name", "mode") as file:

# Code to read/write file

10. List Comprehensions:


[expression for item in iterable if condition]

11. Lambda Functions:

lambda arguments: expression

Example: square = lambda x: x**2

12. Decorators:

@decorator_name

def function_name():

# Code

13. Context Manager:

with expression as variable:

# Code

14. Iterators and Generators:

def generator_function():

yield value

15. Regular Expressions:

import re

re.match(), re.search(), re.findall()

16. Advanced Syntax (Unpacking):

*args, **kwargs

Example: def func(*args, **kwargs):

# Code

You might also like