-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
Syntax refers to the structure and set of rules that define how Python code is written and interpreted.
Python is known for its simple, clean, and readable syntax, which makes it one of the most beginner-friendly programming languages.
Let’s explore the basic rules of Python syntax.
To print text or values in Python:
print("Hello, World!")
Python uses indentation (whitespace) to define blocks of code.
There are no curly braces {}
like other languages.
if 5 > 2:
print("5 is greater than 2") # This line is indented
Incorrect indentation will raise an error.
Use #
to write single-line comments:
# This is a comment
print("Hello")
No need to declare data types:
x = 10
name = "John"
Python is case-sensitive:
a = 10
A = 20
print(a) # Outputs 10
print(A) # Outputs 20
No need to add a semicolon ;
at the end, but it’s allowed:
print("Hello") # Correct
print("Hi");
Separate them using a semicolon:
x = 5; y = 10; print(x + y)
Use \
or parentheses:
total = 1 + 2 + \
3 + 4
Or:
total = (1 + 2 +
3 + 4)
Concept | Example |
---|---|
print("Hello") |
|
Indentation | if x > 0:\n print(x) |
Variable | x = 5 |
Case-sensitive | a ≠ A |
Comment | # This is a comment |
Q1. Write a Python program that prints your name.
Q2. Write a Python program to assign the number 50 to a variable and print its value.
Q3. Write a Python program using indentation with an if
statement to print "Yes"
if a condition is true.
Q4. Create a variable name
and print a greeting using it (e.g., “Hello, John”).
Q5. Write a Python program that includes a comment above a print statement.
Q6. Use a backslash (\
) to break a long line of code into two lines and print a result.
Q7. Assign a float and a string to two different variables and print both.
Q8. Write a Python program to print the sum of two numbers.
Q9. Use one line to declare two variables with values and print both.
Q10. Write a program to show that Python is case-sensitive by creating two variables: a
and A
, and print both.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms