Introduction to Basic Language Syntax - Naresh IT

 

Python Basics: Variable Declarations, Data Types, and Control Structures





1. Variable Declarations in Python

Unlike other languages like Java or C++, Python does not require explicit variable declaration with a specific data type. You can directly assign a value to a variable.

Syntax for Variable Declaration:

python

variable_name = value

 Python is dynamically typed, meaning the type is inferred automatically.

Examples:

python

name = "Grace" # String age = 22 # Integer price = 99.99 # Float is_student = True # Boolean fruits = ["Apple", "Banana"] # List

2. Data Types in Python

Python has several built-in data types. Some common ones are:

Data TypeExampleDescription
intx = 10Whole numbers
floaty = 3.14Decimal numbers
strname = "Sruthi"Text (String)
boolstatus = TrueBoolean values (True/False)
listfruits = ["Apple", "Banana"]Ordered, mutable collection
tuplecoords = (4, 5)Ordered, immutable collection
setunique_nums = {1, 2, 3}Unordered, unique items
dictstudent = {"name": "Grace", "age": 22}Key-Value pairs

Example of Type Checking:

python

x = 10 print(type(x)) # Output: <class 'int'>

3. Control Structures in Python

Control structures allow us to control the flow of execution.

A. Conditional Statements (if, elif, else)

Used for decision-making.

python

age = 18 if age >= 18: print("You are an adult.") elif age > 12: print("You are a teenager.") else: print("You are a child.")

B. Looping Structures

Loops help execute code multiple times.

1. for Loop:
Used for iterating over sequences (list, tuple, range, etc.).

python

for i in range(1, 6): # Loops from 1 to 5 print(i)

2. while Loop:
Runs until the condition is False.

python

count = 1 while count <= 5: print(count) count += 1

3. Loop Control Statements:

  • break → Exits the loop early.
  • continue → Skips the current iteration.
  • pass → Placeholder, does nothing.
python

for i in range(5): if i == 3: continue # Skips 3 print(i)

💡 Are you learning Python? Drop a comment below and let’s grow together! 👇

#Python #LearnPython #Coding #Programming #PythonForBeginners #Tech #Developers #CodeNewbie #PythonCommunity

For More Details Visit : https://nareshit.com/courses/python-online-training

Register For Free Demo on UpComing Batches : https://nareshit.com/new-batches

Comments

Popular posts from this blog

Data Science with Python: Advanced Techniques Using NumPy and Pandas - Naresh IT

Data Analyst Using Power BI: Skills, Tools, and Career Guide - NARESH IT

Full Stack Python Development: The Ultimate Guide to Mastering Web Development - NARESH IT