Basic Syntax
Syntax is the set of rules that defines how code must be written so the computer can understand it. In Python, the syntax is designed to be clean, simple, and readable.
Key Python Syntax Rule
1. Case Sensitivity
–> Python is case-sensitive.
name = "Alice" print(name) # Works print(Name) # Error (different variable)
2. Indentation
–> Python uses indentation (spaces or tabs) to define code blocks.
if True: print("This is indented correctly")
3. Comments
–> Use
# for single-line comments.# This is a comment
print("Hello") # Comment after code
4. Print Statement
Display output with
print().print("Hello, World!")
5. Variables and Assignment
–> No need to declare type; Python figures it out.
x = 10
name = "Jitendra"
6. Strings
–> Use single (‘) or double (“) quotes.
print("Hello")
print('World')
7. Taking Input
–> Use input() to get user input.
name = input("Enter your name: ")
print("Hello,", name)
8. Basic Data Types
-
Numbers:
int,float - Text:
str - True/False:
bool - Collections:
list,tuple,dict
