Python Built-in Functions in Hindi

Python Built-in Functions in Hindi

Built-in Functions ऐसे फंक्शन होते है जो पहले से pre-defined होते है । python में built-in functions को उन functions के रूप में define किया जाता है जिनकी कार्यक्षमता (functionality) pre-defined होती है। python interpreter के कई functions होते हैं, जो हमेशा उपयोग के लिए मौजूद रहते हैं। इन functions को built-in functions के रूप में जाना जाता है। python में कई built-in functions होते हैं जो नीचे सूचीबद्ध हैं:

1. abs() Function

Python abs() Function का उपयोग किसी संख्या के निरपेक्ष मान (absolute value) को return करने के लिए किया जाता है। यह केवल एक argument और एक number लेता हैं जिसका निरपेक्ष मान (absolute value) लौटाता है। argument एक integer और floating-point number हो सकता है। यदि argument एक complex number है, तो, abs() इसका परिमाण लौटाता है।

Syntax : abs(num)

Example –

# random integer

integer = -20


print(‘Absolute value of -20 is:’, abs(integer))

#random floating number

floating = -30.33

print(‘Absolute value of -30.33 is:’, abs(floating))

Output

Absolute value of -20 is: 20


Absolute value of -30.33 is: 30.33

2. all() Function

Python all() function एक iterable object (जैसे list, dictionary आदि) को accept करता है। यदि passed iterable में सभी items true हैं तब यह true return करता है अन्यथा, यह false return करता है। यदि iterable object empty है, तो all ()function true return करता है।

Syntax : all(iterable)

Example –

# all values true

l = [1, 3, 4, 5]

print(all(l))

# all values false

l = [0, False]

print(all(l))

# one false value

l = [1, 3, 4, 0]

print(all(l))

# one true value

l = [0, False, 5]

print(all(l))

# empty iterable

l = []

print(all(l))

Output

True

False

False

False

True

3. bin() Function

python bin () function का उपयोग specific integer के binary representation को return करने के लिए किया जाता है। इसका result हमेशा prefix 0b से शुरू होता है।

Syntax : bin(num)

Example –

number = 5

print(‘The binary equivalent of 5 is:’, bin(number))

Output

The binary equivalent of 5 is: 0b101

4. bool() Function

Python bool() function, standard truth testing procedure का उपयोग करके value को boolean (True or False) में परिवर्तित करता है।

Syntax : bool([value])

Example

test = []

print(test,’is’,bool(test))

test = [0]

print(test,’is’,bool(test))

test = 0.0

print(test,’is’,bool(test))

test = None

print(test,’is’,bool(test))

test = True

print(test,’is’,bool(test))

test = ‘Easy string’

print(test,’is’,bool(test))

Output

[] is False

[0] is True

0.0 is False

None is False

True is True

Easy string is True

5. bytes() Function

python में bytes() का उपयोग bytes object को return करने के लिए किया जाता है। यह bytearray() फ़ंक्शन का अपरिवर्तनीय वर्जन है।

यह specified size के empty bytes object बना सकता है।

Syntax : bytes([source[, encoding[, errors]]])

Example

string = “Python is interesting.”

# string with encoding ‘utf-8’

arr = bytes(string, ‘utf-8’)

print(arr)

Output

b’Python is interesting.’

6. callable() Function

python में callable() function कुछ ऐसा है यह built-in function को check करता है और true लौटाता है यदि pass किया गया object callable हैं, तब यह true लौटाता है अन्यथा false return करता हैं|

Syntax : callable(object)

Example

x = 5

print(callable(x))

def testFunction():

print(“Test”)

y = testFunction

print(callable(y))

Output

False

True

7. compile() Function

python compile() function, Source code को इनपुट के रूप में लेता है और code object देता है जिसे बाद में exec() function द्वारा execute किया जा सकता है।

syntax : compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)

Example

codeInString = ‘a = 5\nb=6\nsum=a+b\nprint(“sum =”,sum)’

codeObejct = compile(codeInString, ‘sumstring’, ‘exec’)

exec(codeObejct)

Output

sum = 11

8. exec() Function

python exec() function का उपयोग python प्रोग्राम के dynamic execution के लिए किया जाता है जो या तो string या object code हो सकता है और यह code के बड़े ब्लॉक को स्वीकार करता है, इसके विपरीत eval () फ़ंक्शन जो केवल single expression को accept करता है।

syntax : exec(object, globals, locals)

Example

program = ‘a = 5\nb=10\nprint(“Sum =”, a+b)’

exec(program)

Output

Sum = 15

9. sum() Function

जैसा कि नाम से पता चलता है, python sum() function का उपयोग iterable, यानी list की संख्याओं का योग प्राप्त करने के लिए किया जाता है।

Syntax : sum(iterable, start)

Example

marks = [65, 71, 68, 74, 61]

# find sum of all marks

total_marks = sum(marks)

print(total_marks)

Output:
339

10. any() Function

यदि किसी iterable में कोई item true है तो python any() function, true return करता है। अन्यथा, यह false return करता है।

Syntax : any(iterable)

Example

# True since 1,3 and 4 (at least one) is true

l = [1, 3, 4, 0]

print(any(l))

# False since both are False

l = [0, False]

print(any(l))

# True since 5 is true

l = [0, False, 5]

print(any(l))

# False since iterable is empty

l = []

print(any(l))

Output

True

False

True

False

11. ascii() Function

ASCII का मतलब American Standard Code for Information Interchange है। यह एक वर्ण एन्कोडिंग मानक है जो अंग्रेजी वर्णों का प्रतिनिधित्व करने के लिए 0 से 127 तक की संख्याओं का उपयोग करता है। उदाहरण के लिए, A के लिए ASCII कोड 65 है, और Z के लिए 90 है। इसी तरह, ASCII कोड 97, a के लिए है, और 122, z के लिए है। ASCII कोड का उपयोग tab, form feed, carriage return और कुछ symbols जैसे वर्णों का प्रतिनिधित्व करने के लिए भी किया जाता है।

पायथन में ascii () method, non-alphabets और invisible characters जैसे tab, carriage return, form feed इत्यादि के लिए किसी ऑब्जेक्ट के प्रिंट करने योग्य एक स्ट्रिंग देता है। और \x, \u या \U एस्केप का उपयोग करके स्ट्रिंग में non-ASCII वर्णों से बच निकलता है।

Syntax : ascii(object)

Example

normalText = ‘Python is interesting’

print(ascii(normalText))

otherText = ‘Pythön is interesting’

print(ascii(otherText))

print(‘Pyth\xf6n is interesting’)

Output:

‘Python is interesting’

‘Pyth\xf6n is interesting’

Pythön is interesting

 12. bytearray() Function

Python bytearray() एक bytearray object देता है और यह objects को bytearray objects में परिवर्तित कर सकता है, या specified size की empty bytearray को object बना सकता है।

Syntax : bytearray([source[, encoding[, errors]]])

Example

string = “Python is interesting.”

# string with encoding ‘utf-8’

arr = bytearray(string, ‘utf-8’)

print(arr)

Output

bytearray(b’Python is interesting.’)

13. eval() Function

Python eval() Function इसे pass किये गए expression को parse करता है और प्रोग्राम के अन्दर python expression(code) चलाता है।

Syntax : eval(expression, globals=None, locals=None)

Example

x = 1

print(eval(‘x + 1’))

Output

2

14. float() Function

python float() function किसी number या string से floating-point number देता है।

Syntax : float([x])

Example

# for integers

print(float(10))

# for floats

print(float(11.22))

# for string floats

print(float(“-13.33”))

Output

10.0

11.22

-13.33

15. Format() Function

Python format() function दी गई value का formatted representation देता है।

Syntax : format(value[, format_spec])

Example

# d, f and b are type

# integer

print(format(123, “d”))

# float arguments

print(format(123.4567898, “f”))

# binary format

print(format(12, “b”))

Output

123

123.456790

1100

16. frozenset() Function

python frozenset() function अपरिवर्तनीय frozenset object देता है जो दिए गए iterable elements के साथ आरंभ किया जाता है।

Syntax : frozenset([iterable])

Example

# tuple of vowels

vowels = (‘a’, ‘e’, ‘i’, ‘o’, ‘u’)

fSet = frozenset(vowels)

print(‘The frozen set is:’, fSet)

print(‘The empty frozen set is:’, frozenset())

# frozensets are immutable

fSet.add(‘v’)

Output

The frozen set is: frozenset({‘a’, ‘o’, ‘u’, ‘i’, ‘e’})

The empty frozen set is: frozenset()

Traceback (most recent call last):

File “<string>, line 8, in <module>

fSet.add(‘v’)

AttributeError: ‘frozenset’ object has no attribute ‘add’

17. getattr() Function

Python getattr () function किसी object की named attribute की value देता है। यदि यह नहीं मिला है, तो यह डिफ़ॉल्ट मान लौटाता है।

Syntax : getattr(object, name[, default])

Example

class Person:

age = 20

name = “Shiva”

person = Person()

print(‘The age is:’, getattr(person, “age”))

print(‘The age is:’, person.age)

Output

The age is: 20

The age is: 20

18. globals() Function

Python globals() Function वर्तमान global symbol table का शब्दकोश देता है। Symbol Table को data structure के रूप में परिभाषित किया जाता है जिसमें prgram के बारे में सभी आवश्यक जानकारी होती है। इसमें variable names, methods, classes आदि शामिल हैं।

Example

age = 30

globals()[‘age’] = 30

print(‘The age is:’, age)

Output:

The age is: 30

19. iter() Function

Python iter() Function का उपयोग iterator object को return करने के लिए किया जाता है। यह एक ऐसा ऑब्जेक्ट बनाता है जिसे एक समय में एक element को iterate किया जा सकता है।

Example

# list of vowels

vowels = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]

vowels_iter = iter(vowels)

print(next(vowels_iter))    # ‘a’

print(next(vowels_iter))    # ‘e’

print(next(vowels_iter))    # ‘i’

print(next(vowels_iter))    # ‘o’

print(next(vowels_iter))    # ‘u’

Output

a

e

i

o

u

19. len() Function

Python len() Function का उपयोग किसी ऑब्जेक्ट की लंबाई (आइटम की संख्या) को return करने के लिए किया जाता है।

Example

strA = ‘Python’

print(len(strA))

Output:

6

20. list() Function

पाइथन में list() function का प्रयोग list बनाने के लिए किया जाता है।

Example

# empty list

print(list())

# string

String = ‘abcde’
print(list(String))

# tuple

Tuple = (1,2,3,4,5)

print(list(Tuple))

# list

List = [1,2,3,4,5]

print(list(List))

Output:

[]

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

[1,2,3,4,5]

[1,2,3,4,5]

error: Content is protected !!