Wednesday, 22 January 2025

Python basics

 <script type="text/javascript" src="https://udbaa.com/bnr.php?section=General&pub=174668&format=728x90&ga=g"></script>

<noscript><a href="https://yllix.com/publishers/174668" target="_blank"><img src="//ylx-aff.advertica-cdn.com/pub/728x90.png" style="border:none;margin:0;padding:0;vertical-align:baseline;" alt="ylliX - Online Advertising Network" /></a></noscript>

<br>

<br>



1. Variables (चर):


Variables ko hum data ko store karne ke liye use karte hain.

Example:


x = 5 # x mein 5 store kar rahe hain


2. Data Types (डेटा प्रकार):


Python mein kai types ke data hote hain, jaise:


Integer (पूरा अंक):


age = 25 # integer type


Float (दशमलव अंक):


price = 19.99 # float type


String (स्ट्रिंग):


name = "Amit" # string type


Boolean (बूलियन):


is_active = True # boolean type



3. Operators (संचालक):


Python mein kuch basic operators hain, jo hum values par operations karne ke liye use karte hain:


Addition (+):


a = 10

b = 5

result = a + b # result = 15


Subtraction (-):


result = a - b # result = 5


Multiplication (*):


result = a * b # result = 50


Division (/):


result = a / b # result = 2.0



4. If Statement (यदि कथन):


if statement ko hum condition check karne ke liye use karte hain. Example:


age = 18

if age >= 18:

    print("Aap Vayask hain") # Agar age 18 ya zyada hai toh yeh print hoga

else:

    print("Aap Nabalig hain") # Agar age 18 se kam hai toh yeh print hoga


5. Loops (लूप):


Loop ka use kisi code ko baar-baar chalane ke liye hota hai.


For Loop:


for i in range(5): # yeh 0 se lekar 4 tak print karega

    print(i)


While Loop:


count = 0

while count < 5:

    print(count)

    count += 1 # count ko 1 badhate hain



6. Functions (कार्य):


Functions ka use hum code ko modular banane ke liye karte hain, taaki hum ek task ko baar-baar call kar sakein. Example:


def greet(name):

    print("Namaste, " + name)


greet("Amit") # yeh 'Namaste, Amit' print karega


7. Lists (सूची):


List ka use hum ek se adhik cheezon ko store karne ke liye karte hain. Example:


fruits = ["Apple", "Banana", "Mango"]

print(fruits[0]) # yeh "Apple" print karega


8. Dictionaries (शब्दकोश):


Dictionaries ka use key-value pairs ko store karne ke liye hota hai. Example:


person = {"name": "Amit", "age": 25}

print(person["name"]) # yeh "Amit" print karega


9. Comments (टिप्पणियाँ):


Comments ka use hum code ko samjhane ke liye karte hain, jo Python interpreter ignore karta hai. Example:


# Yeh ek comment hai

print("Hello, World!") # Yeh line screen par print karegi


10. Input (इनपुट):


User se input lene ke liye input() functi

on ka use karte hain. Example:


name = input("Apna naam daalein: ")

print("Namaste, " + name)

No comments:

Post a Comment

Technology News

Technology News Private Sector AI Infrastructure Investment: President Donald Trump announced a joint venture called Stargate, involvi...