Basic Syntax of Python in Hindi

Python का syntax बहुत ही सरल और readable होता है। इस language में indentation का बहुत महत्व है, और यह syntax को बहुत clean बनाता है। यहां पाइथन के कुछ मुख्य syntax दिए गए हैं:

1. प्रिंट स्टेटमेंट (Print Statement)

पाइथन में print() function का उपयोग output दिखाने के लिए किया जाता है।

उदाहरण:

print("Hello, World!")

यह output में “Hello, World!” दिखाएगा।

2. Variables

पाइथन में variables को declare करने के लिए किसी भी विशेष keyword की जरूरत नहीं होती। सीधे variable name और value को लिखने से variable बन जाता है।

उदाहरण:

x = 10
name = "Yugal"

यहां x में 10 और name में “Yugal” स्टोर हो गया।

3. Data Types

पाइथन में कुछ सामान्य data types होते हैं, जैसे:

  • int – integer numbers
  • float – decimal numbers
  • str – text या strings
  • bool – Boolean values (True, False)

उदाहरण:

a = 5       # int

b = 3.14    # float

c = "Hello" # string

d = True    # boolean

4. Functions

पाइथन में functions को def कीवर्ड का उपयोग करके define किया जाता है।

उदाहरण:

def greet(name):

    print("Hello, " + name + "!")

greet("Yugal")

यहां greet function एक नाम input लेता है और उसे print करता है।

5. List, Tuple, and Dictionary

List

fruits = ["apple", "banana", "cherry"]

Tuple

coordinates = (4, 5)

Dictionary

student = {"name": "Yugal", "age": 25}

6. Indentation

पाइथन में indentation बहुत जरूरी है क्योंकि यह blocks को define करता है। किसी भी block की शुरुआत एक समान space से होनी चाहिए। गलत indentation syntax error देता है।

if age >= 18:

    print("You are eligible to vote.")   # सही इंडेंटेशन

  # print("This will cause an error")   # गलत इंडेंटेशन

7. Comments

पाइथन में comments कोड में notes जोड़ने के लिए उपयोग किए जाते हैं, जो कि program के execution को प्रभावित नहीं करते। Comments को # symbol से शुरू किया जाता है।

# This is Comment

Multi-Line Comments के लिए ”’ या “”” का उपयोग किया जा सकता है:

'''

This is

Multi-Line

Comment

'''

Leave a Comment