0% found this document useful (0 votes)
14 views2 pages

Python Basic Syntax

Uploaded by

zaheerkhan223347
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)
14 views2 pages

Python Basic Syntax

Uploaded by

zaheerkhan223347
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

Python Basic Syntax

Comments
• # This is a single-line comment
• """This is a multi-line comment"""

Variables
• x=5
• name = 'Iqra'
• pi = 3.14

Data Types
• int, float, str, list, tuple, dict, set, bool

Conditional Statements
• if condition:
• # code block
• elif condition:
• # code block
• else:
• # code block

Loops
• for i in range(5):
• print(i)
• while condition:
• # code block

Functions
• def function_name(parameters):
• # code block
• return value

Classes and Objects


• class MyClass:
• def __init__(self, name):
• [Link] = name
• def greet(self):
• print('Hello', [Link])
• obj = MyClass('Iqra')
• [Link]()
Importing Modules
• import math
• print([Link](16))

Exception Handling
• try:
• # code block
• except Exception as e:
• print(e)
• finally:
• # code block

You might also like