Skip to main content

Posts

Showing posts from 2024

Input and Output statements in Python

In Python, input and output are handled using built-in functions input() and print(). पायथन में, इनपुट और आउटपुट को अंतर्निहित फ़ंक्शन इनपुट() और प्रिंट() का उपयोग करके नियंत्रित किया जाता है। 1.) input():- To take input from the user, we can use the `input()` function. This function reads a line usually from a standard input device (keyboard) and returns it as a string to a variable. By default, `input()` returns data as a string, so if we need an integer or a float, we must convert it by type conversion. 1.) इनपुट():- उपयोगकर्ता से इनपुट लेने के लिए, हम `इनपुट()` फ़ंक्शन का उपयोग कर सकते हैं। यह फ़ंक्शन आमतौर पर एक मानक इनपुट डिवाइस (कीबोर्ड) से एक लाइन पढ़ता है और इसे एक स्ट्रिंग के रूप में एक वेरिएबल में लौटाता है। डिफ़ॉल्ट रूप से, `इनपुट()` डेटा को एक स्ट्रिंग के रूप में लौटाता है, इसलिए यदि हमें इंटीजर या फ्लोट की आवश्यकता है, तो हमें इसे टाईप कन्वर्जन द्वारा परिवर्तित करना होगा। 2.) print():- To display output to the user, we can use the `print()` function. 2.) प्रिंट():-  उ...

Reduce function of python

reduce function The reduce function in Python allows us to apply a specific operation to a sequence of elements and reduce them into a single value. It takes two parameters: a function and an iterable object, such as a list or tuple. Syntax reduce(function, iterable) Let's say you have a list of numbers and you want to find their sum. You can use the reduce function to achieve this in a concise manner. from functools import reduce numbers = [1, 2, 3, 4, 5] result = reduce(lambda x, y: x + y, numbers) print(result) Output 15 In this example, the reduce function takes a lambda function as the first argument, which adds two numbers together. It applies this lambda function cumulatively to the list of numbers, combining them into a single result. In the end, we get the sum of all the numbers. Let's consider another scenario. Suppose we have a list of numbers and we want to find the maximum value. The reduce function can help us achieve this with ease. from functools import reduce n...

Filter function of python

filter function:-  Imagine we have a bunch of things, like a list of numbers, a collection of fruits, or any other group of items. Now, let's say we want to pick out only certain items from that group based on a specific condition. This is where the filter function comes in handy. Let's say we have a list of numbers, and we want to filter out only the even numbers. We define a condition-checking function that checks if a number is even. Then, we pass this function and the list of numbers to the filter function. It goes through each number, applies the condition-checking function, and keeps only the numbers that are even. Finally, it gives us a new list containing only the even numbers. def is_even(num):     return num % 2 == 0 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] filtered_numbers = list(filter(is_even, numbers)) print(filtered_numbers) Output [2, 4, 6, 8, 10] We can also utilize lambda expressions to define filtering conditions directly within the filter function. nu...

Map function of Python

map() function The map() function takes two arguments: a function and an iterable (such as a list, tuple, or string). It applies the function to each element of the iterable and returns a new iterable with the transformed values. Syntax map(function, iterable) Let's say we have a list of numbers, and we want to square each number in the list. Instead of writing a loop to iterate through the list and square each number, we can simply use the map() function to achieve the same result in a more concise way. numbers = [1, 2, 3, 4, 5] squared_numbers = list(map(lambda x: x**2, numbers)) print(squared_numbers) Output [1, 4, 9, 16, 25] Here, we passed a lambda function (a small anonymous function) as the first argument to map(). This lambda function takes a single argument x and returns the square of that number. The map() function applies this lambda function to each element in the numbers list and returns a new iterable, which we convert into a list using the list() function. Using the ...

Lambda Function of Python पायथन में लैम्ब्डा फ़ंक्शंस

Lambda functions, also known as anonymous functions that are one-line functions without a name. They are defined using the lambda keyword and are primarily used when a small function is required for a short period. Lambda functions can take any number of arguments but can only have a single expression. लैम्ब्डा फ़ंक्शंस, जिन्हें अनाम फ़ंक्शंस के रूप में भी जाना जाता है, जो बिना नाम के एक-पंक्ति फ़ंक्शंस हैं। उन्हें लैम्ब्डा कीवर्ड का उपयोग करके परिभाषित किया गया है और मुख्य रूप से तब उपयोग किया जाता है जब छोटी अवधि के लिए एक छोटे फ़ंक्शन की आवश्यकता होती है। लैम्ब्डा फ़ंक्शंस किसी भी संख्या में तर्क ले सकते हैं लेकिन केवल एक ही अभिव्यक्ति हो सकती है। Syntax:- lambda arguments: expression Example:- double = lambda x: x * 2 print(double(5))  #Output=10 sum = lambda a, b: a + b print(sum(3, 4))  #Output=7

Flow of execution of a python program पाइथन प्रोग्राम के निष्पादन का प्रवाह

Flow of execution represents a general outline of Python program execution. The specific flow can vary based on the program's structure, control flow statements (if, else, for, while), and function calls. निष्पादन का प्रवाह पायथन प्रोग्राम निष्पादन की एक सामान्य रूपरेखा का प्रतिनिधित्व करता है। विशिष्ट प्रवाह प्रोग्राम की संरचना, नियंत्रण प्रवाह विवरण (यदि, अन्यथा, के लिए, जबकि), और फ़ंक्शन कॉल के आधार पर भिन्न हो सकता है। 1.) Start: The program begins execution. 1.) प्रारंभ: प्रोग्राम का निष्पादन प्रारंभ होता है। 2.) Import Modules: If necessary, the program imports external modules or libraries. 2.) मॉड्यूल आयात करें: यदि आवश्यक हो, तो प्रोग्राम बाहरी मॉड्यूल या लाइब्रेरी आयात करता है। 3.) Define Functions: Any functions used in the program are defined. 3.) फंक्शन्स को परिभाषित करें: प्रोग्राम में उपयोग किए गए किसी भी फंक्शन को परिभाषित किया जाता है। 4.) Main Program: The main body of the program starts. 4.) मुख्य प्रोग्राम: प्रोग्राम का मुख्य भाग प्रारंभ होता है। 5.) Initializat...

Operator's in Python पायथन में ऑपरेटर्स

Python supports various types of operators for performing operations on variables and values. Here are some common types of operators in Python: पायथन वेरिएबल्स और मानों पर संचालन करने के लिए विभिन्न प्रकार के ऑपरेटरों का समर्थन करता है। यहां पायथन में कुछ सामान्य प्रकार के ऑपरेटर हैं: 1. Arithmetic Operators:    + # Addition     - # Subtraction    * # Multiplication    / # Division    % # Modulus (remainder)    ** # Exponentiation    // # Floor Division 2. Comparison Operators:        == # Equal to    != # Not equal to    < # Less than    > # Greater than    <= # Less than or equal to    >= # Greater than or equal to     3. Logical Operators:       and # Logical AND    or # Logical OR    not # Logical NOT    4. Assignment Operators:    ...

Statements in Python पायथन में कथन

In Python, statements are individual instructions that the interpreter can execute. Here are some common types of statements: पायथन में, कथन व्यक्तिगत निर्देश होते हैं जिन्हें दुभाषिया निष्पादित कर सकता है। यहां कुछ सामान्य प्रकार के कथन दिए गए हैं: 1. Assignment Statement:     x = 10 2. Conditional Statement (if-else):    if x > 5:        print("x is greater than 5")    else:        print("x is not greater than 5") 3. Looping Statements (for and while):    for i in range(5):        print(i)    while x > 0:        print(x)        x -= 1 4. Function Definition:    def greet(name):        print("Hello, " + name + "!") 5. Import Statement:     import math     These are just a few examples, and there are many other types of statements in Python. Each statement serves a specific purpose an...

Expressions in Python पायथन में अभिव्यक्तियां

In Python, an expression is a combination of values, variables, operators, and function calls that results in a single value. Expressions can be as simple as a single variable or as complex as a mathematical formula. Expressions are the building blocks of Python programs and are used to perform calculations, make decisions, and manipulate data. Here are some examples: पायथन में, एक अभिव्यक्ति मानों, चर, ऑपरेटरों और फ़ंक्शन कॉल का एक संयोजन है जिसके परिणामस्वरूप एकल मान प्राप्त होता है। अभिव्यक्तियाँ एकल चर जितनी सरल या गणितीय सूत्र जितनी जटिल हो सकती हैं। अभिव्यक्तियाँ पायथन कार्यक्रमों के निर्माण खंड हैं और गणना करने, निर्णय लेने और डेटा में हेरफेर करने के लिए उपयोग की जाती हैं। यहां कुछ उदाहरण दिए गए हैं: 1. Arithmetic Expression:      result = 3 + 5 * 2 2. Boolean Expression:      is_greater = (10 > 5) #is_greater=True  3. String Concatenation:    greeting = "Hello, " + "World!" 4. Function Call in an Expression:    lengt...

Variables in python पायथन में वेरिएबल

In Python, variables are used to store and manage data/values. You can create a variable by assigning a value to it. For example: पायथन में, वेरिएबल्स का उपयोग डेटा/मानों को संग्रहीत और प्रबंधित करने के लिए किया जाता है। आप इसमें एक मान निर्दिष्ट करके एक वेरिएबल बना सकते हैं। उदाहरण के लिए: my_variable = 50 Here, `my_variable` is a variable storing the value `50`.  यहां, `my_variable` `50` मान संग्रहीत करने वाला एक वैरिएबल है। Variable names are case-sensitive and can include letters, numbers, and underscores, but they must start with a letter(a to z, A to Z) or underscore(_). परिवर्तनीय नाम केस-संवेदी होते हैं और उनमें अक्षर, संख्याएं और अंडरस्कोर शामिल हो सकते हैं, लेकिन उन्हें अक्षर (a से z, A से Z) या अंडरस्कोर (_) से शुरू होना चाहिए। In Python, We can reassign variables with new values of any type: पायथन में, हम किसी भी प्रकार के नए मानों के साथ वेरिएबल्स को पुन: असाइन कर सकते हैं: my_variable = "Hello, Python!" Now, `my_variable` contains the string "Hello, Python!...

Installation process of Python IDLE पायथन आईडीएलई की इंस्टालेशन प्रक्रिया

Steps for installing Python with IDLE:- IDLE के साथ Python इंस्टॉल करने के चरण:-  1. Download Python:- First Visit the official Python website at [python.org](https://www.python.org/). and Here Navigate to the "Downloads" section. 1. पायथन डाउनलोड करें:- सबसे पहले आधिकारिक पायथन वेबसाइट [python.org](https://www.python.org/) पर जाएं। और यहां "डाउनलोड" अनुभाग पर जाएं। 2. Choose Python Version:- Choose the Python version suitable for your needs (e.g., Python 3.x) and Download the installer for your operating system (Windows, macOS, or Linux). 2. पायथन संस्करण चुनें:- अपनी आवश्यकताओं के लिए उपयुक्त पायथन संस्करण चुनें (उदाहरण के लिए, पायथन 3.x) और अपने ऑपरेटिंग सिस्टम (विंडोज़, मैकओएस, या लिनक्स) के लिए इंस्टॉलर डाउनलोड करें।  3. Run Installer:- Run the downloaded installer and During the installation process, you might see an option to "Add Python to PATH." It's recommended to check this option as it makes it easier to run Python from the command line. 3....

Basic Data Types of Python पायथन के बेसिक डेटा टाइप

Data types are an essential part of any programming language as they define the type of data that can be stored in a variable. Python supports several built-in data types, including numeric, boolean, sequence, dictionary, and set data types. डेटा प्रकार किसी भी प्रोग्रामिंग भाषा का एक अनिवार्य हिस्सा हैं क्योंकि वे डेटा के प्रकार को परिभाषित करते हैं जिसे एक चर में संग्रहीत किया जा सकता है। पायथन कई अंतर्निहित डेटा प्रकारों का समर्थन करता है, जिनमें संख्यात्मक, बूलियन, अनुक्रम, शब्दकोश और सेट डेटा प्रकार शामिल हैं। In Python, data types are dynamic, meaning the data type of a variable can change at runtime depending on the type of value assigned to it. For example, a variable declared as an integer can later be assigned a string value, and Python will change its data type to a string automatically. पायथन में, डेटा प्रकार गतिशील होते हैं, जिसका अर्थ है कि किसी वेरिएबल का डेटा प्रकार उसे निर्दिष्ट मान के प्रकार के आधार पर रनटाइम पर बदल सकता है। उदाहरण के लिए, पूर्णांक के रूप में घोषित एक...

The Python Interpreter पायथन इंटरप्रेटर

The Python interpreter is a program that executes Python code. It reads and interprets Python scripts or interactive commands, converting them into machine-readable bytecode for the computer to execute.The interpreter is a crucial component for running Python code, facilitating both learning and development processes. Users can interact with the interpreter in two primary modes: पायथन इंटरप्रेटर एक प्रोग्राम है जो पायथन कोड को निष्पादित करता है। यह पायथन स्क्रिप्ट या इंटरैक्टिव कमांड को पढ़ता है और व्याख्या करता है, उन्हें कंप्यूटर द्वारा निष्पादित करने के लिए मशीन-पठनीय बाइटकोड में परिवर्तित करता है। दुभाषिया पायथन कोड चलाने के लिए एक महत्वपूर्ण घटक है, जो सीखने और विकास दोनों प्रक्रियाओं को सुविधाजनक बनाता है। उपयोगकर्ता इंटरप्रेटर के साथ दो प्राथमिक मोड में बातचीत कर सकते हैं:- 1. Interactive Mode:- In this mode we can launch the Python interpreter in our terminal or command prompt without specifying a script.This mode allows us to enter Python commands and see immediate results...

Dynamically typed and strongly typed features of python गतिशील रूप से टाइप और दृढ़ता से टाइप की गई भाषा पायथन

Python is both dynamically typed and strongly typed programming language. Here's what each of these terms means:- पायथन गतिशील रूप से टाइप की गई और दृढ़ता से टाइप की गई प्रोग्रामिंग भाषा है। यहां बताया गया है कि इनमें से प्रत्येक शब्द का क्या अर्थ है:-  1. Dynamically Typed:-  In Python, variable types are determined at runtime, not during compilation.It means You don't need to explicitly declare the data type of a variable; it is inferred based on the value assigned to it. For example, you can assign an integer to a variable, and later, without redeclaring, assign a string to the same variable.    x = 5            # x is an integer    x = "hello"   # x is now a string 1. गतिशील रूप से टाइप किया गया:- पायथन में, वेरिएबल प्रकार रनटाइम पर निर्धारित होते हैं, संकलन के दौरान नहीं। इसका मतलब है कि आपको किसी वेरिएबल के डेटा प्रकार को स्पष्ट रूप से घोषित करने की आवश्यकता नहीं है; इसका अनुमान उसे दिए गए मान के आधार पर लगाया ज...

Python IDLE पायथन आईडीएलई (इंटीग्रेटेड डेवलपमेंट एंड लर्निंग एनवायरनमेंट)

IDLE (Integrated Development and Learning Environment) is a graphical user interface (GUI) for the Python programming language. It includes the Python standard library and provides a convenient environment for writing, running, and debugging Python code. IDLE (इंटीग्रेटेड डेवलपमेंट एंड लर्निंग एनवायरनमेंट) पायथन प्रोग्रामिंग भाषा के लिए एक ग्राफिकल यूजर इंटरफेस (GUI) है। इसमें पायथन मानक लाइब्रेरी शामिल है और पायथन कोड लिखने, चलाने और डीबग करने के लिए एक सुविधाजनक वातावरण प्रदान करता है।  Key features of IDLE are:- आईडीएलई की मुख्य विशेषताएं हैं:-  1. Interactive Shell:- IDLE provides an interactive Python shell, allowing you to execute Python commands and see the immediate results. 1. इंटरएक्टिव शेल:- आईडीएलई एक इंटरैक्टिव पायथन शेल प्रदान करता है, जो आपको पायथन कमांड निष्पादित करने और तत्काल परिणाम देखने की अनुमति देता है।  2. Script Editor:- It includes a text editor for writing Python scripts. You can create, edit, and save Python files with a ".py" extension. 2. स्क्...

python program for factorial of given number.

def factorial(n):     if n == 0 or n == 1:         return 1     else:         return n * factorial(n-1) # Input: Enter the value of 'num' to calculate the factorial for a different number num = int(input("Enter a positive Integer"))  if(num>=0)  result = factorial(num) print("The factorial of {num} is: {result}")