Skip to main content

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.
पायथन में, डेटा प्रकार गतिशील होते हैं, जिसका अर्थ है कि किसी वेरिएबल का डेटा प्रकार उसे निर्दिष्ट मान के प्रकार के आधार पर रनटाइम पर बदल सकता है। उदाहरण के लिए, पूर्णांक के रूप में घोषित एक चर को बाद में एक स्ट्रिंग मान सौंपा जा सकता है, और पायथन अपने डेटा प्रकार को स्वचालित रूप से एक स्ट्रिंग में बदल देगा।

1.) Numeric Data Types:-

Numeric data types are used to store numeric values such as integers, floating-point numbers, and complex numbers.
संख्यात्मक डेटा प्रकारों का उपयोग संख्यात्मक मानों जैसे पूर्णांक, फ़्लोटिंग-पॉइंट संख्या और जटिल संख्याओं को संग्रहीत करने के लिए किया जाता है।

a) Integer इन्टिजर :-
Integers are whole numbers with no fractional part, and they are represented in Python using the `int` data type.
पूर्णांक पूर्ण संख्याएँ हैं जिनमें कोई भिन्नात्मक भाग नहीं होता है, और उन्हें `int` डेटा प्रकार का उपयोग करके पायथन में दर्शाया जाता है। 
Here is an example यहाँ एक उदाहरण है:-

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


b) Float फ्लोट:-
Floating-point numbers are used to represent decimal numbers, and they are represented in Python using the `float` data type. 
फ्लोटिंग-पॉइंट संख्याओं का उपयोग दशमलव संख्याओं को दर्शाने के लिए किया जाता है, और उन्हें `फ्लोट` डेटा प्रकार का उपयोग करके पायथन में दर्शाया जाता है। 
Here is an example यहाँ एक उदाहरण है:-

x = 3.14

print(type(x)) # Output: <class 'float'>

c) Complex काम्प्लेक्स:-
Complex numbers are used to represent numbers with both real and imaginary parts, and they are represented in Python using the `complex` data type. 

Here is an example:

x = 2 + 3j

print(type(x)) # Output: <class 'complex'>

```

Boolean Data Type:-

Boolean data types are used to represent the truth values `True` and `False`. In Python, boolean values are represented using the `bool` data type. Here is an example:

```

x = True

print(type(x)) # Output: <class 'bool'>

```

2.) Sequence Data Types:-

Sequence data types are used to store sequences of elements such as characters, lists, and tuples.

String:-

Strings are used to represent text data in Python, and they are represented using the `str` data type. Here is an example:

```

x = "Hello, World!"

print(type(x)) # Output: <class 'str'>

```

List:-

Lists are used to store a collection of elements, and they are represented using the `list` data type. Lists are mutable, meaning their elements can be changed after they are created. Here is an example:

```

x = [1, 2, 3, 4]

print(type(x)) # Output: <class 'list'>

```

Tuple:-

Tuples are used to store a collection of elements, and they are represented using the `tuple` data type. Tuples are immutable, meaning their elements cannot be changed after they are created. Here is an example:

```

x = (1, 2, 3, 4)

print(type(x)) # Output: <class 'tuple'>
## Tuples
Tuples are a type of sequence in Python that can hold any number of elements of different data types, just like lists. However, tuples are immutable, which means that once you create a tuple, you cannot modify its contents. The syntax for creating a tuple is to enclose a sequence of values in parentheses, separated by commas.


### Example:
```python
my_tuple = (1, "hello", 3.14)
```


### Accessing Tuple Elements
Tuple elements can be accessed using their index, just like lists. The first element of a tuple has an index of 0, the second element has an index of 1, and so on.


### Example:
```python
my_tuple = (1, "hello", 3.14)
print(my_tuple[0]) # Output: 1
print(my_tuple[1]) # Output: "hello"
```


### Tuple Operations
While you cannot modify the contents of a tuple, you can perform operations on tuples, such as concatenation and repetition.


#### Concatenation:
```python
tuple1 = (1, 2, 3)
tuple2 = (4, 5, 6)
tuple3 = tuple1 + tuple2
print(tuple3) # Output: (1, 2, 3, 4, 5, 6)
```


#### Repetition:
```python
tuple1 = (1, 2, 3)
tuple2 = tuple1 * 3
print(tuple2) # Output: (1, 2, 3, 1, 2, 3, 1, 2, 3)
```


### Advantages of Tuples
- Tuples are immutable, which means that once you create a tuple, you cannot modify its contents. This makes tuples a good choice for storing data that should not be modified, such as configuration settings or constant values.
- Tuples are faster than lists when it comes to indexing and iterating over large collections of data.
- Tuples can be used as keys in dictionaries, while lists cannot.


## Sets
A set is an unordered collection of unique elements in Python. In other words, a set contains no duplicate elements. You can create a set by enclosing a sequence of values in curly braces, separated by commas.


### Example:
```python
my_set = {1, 2, 3, 4}
```


### Adding Elements to a Set
You can add elements to a set using the `add()` method.


### Example:
```python
my_set = {1, 2, 3}
my_set.add(4)
print(my_set) # Output: {1, 2, 3, 4}
```


### Removing Elements from a Set
You can remove elements from a set using the `remove()` method.


### Example:
```python
my_set = {1, 2, 3, 4}
my_set.remove(3)
print(my_set) # Output: {1, 2, 4}
```


### Set Operations
Sets support a variety of operations, such as union, intersection, and difference.


#### Union:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
set3 = set1.union(set2)
print(set3) # Output: {1, 2, 3, 4}
```


#### Intersection:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
set3 = set1.intersection(set2)
print(set3) # Output: {2, 3}
```


####

Python has several basic data types, including:-
पायथन में कई बुनियादी डेटा प्रकार हैं, जिनमें शामिल हैं:-

1. Integers (`int`):- Whole numbers without decimal points.
पूर्णांक (`int`):- दशमलव बिंदु के बिना पूर्ण संख्याएँ। 

x = 5

2. Floating points (`float`):- Numbers with decimal points.
फ़्लोटिंग पॉइंट ('फ़्लोट'):- दशमलव बिंदु वाली संख्याएँ। 

y = 3.14

3. Strings (`str`):- Sequences of characters, enclosed in single or double quotes.
स्ट्रिंग्स (`str`):- एकल या दोहरे उद्धरण चिह्नों में संलग्न वर्णों का अनुक्रम। 

message = "Hello, Python!"

4. Booleans (`bool`):- Representing True or False values.
बूलियन्स ('बूल'):- सही(True) या गलत(False) मूल्यों का प्रतिनिधित्व करना। 

is_true = True

5. Lists (`list`):- Ordered, mutable collections of different types of elements.
सूचियाँ (`सूची`):- विभिन्न प्रकार के तत्वों का क्रमबद्ध, परिवर्तनशील संग्रह। 

numbers = [1, "ajay", 340.5]

6. Tuples (`tuple`):- Ordered, immutable collections of elements.
टपल्स ('ट्यूपल'):- तत्वों का क्रमबद्ध, अपरिवर्तनीय संग्रह।

coordinates = (30.458, 75.186)

7. Dictionaries (`dict`):- Unordered collections of key-value pairs.
शब्दकोष ('dict'):- कुंजी-मूल्य युग्मों का अव्यवस्थित संग्रह। 

person = {'name': 'John', 'age': 25}

8. Sets (`set`):- Unordered collections of unique elements.
सेट ('सेट'):- अद्वितीय तत्वों का अव्यवस्थित संग्रह।

unique_numbers = {1, 2, 3, 4}


Comments

Popular posts from this blog

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...

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...

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