Please support if you like my work by payment through upi: sinhamit@icici or payment by bank
account name: Amit Kumar Sinha,
account number: 2646728782
IFSC code: KKBK0005660
SWIFT: KKBKINBB
builtins module in Category: Python by amit
🕙 Posted on 2023-06-26 at 12:19:38 Read in Hindi ...
Built-in Functions
Unlike PHP and JavaScript, there are many modules (libraries) in Python, and even you can contribute or create your own custom modules. One of those modules is builtins which defines all built-in functions in the python programming language. To exploit all features of a module, you have to import it in your file with .py extension, and run/
import
builtins
print( dir( builtins
) ) # Outputs following built-in functions as items of a list
PS C:\xampp\
import
builtins
print( help( builtins ) ) # You can run/help( builtins )
outputs very large help data, and therefore, you should extract separate help for each of these built-in functions mentioned above.
Each of these built-in functions have their own methods, some of those methods have same name for different built-in functions. You can see names of methods of respective built-in function, by executing the statement, for example, print( dir( list
) ) or print( dir( str
) ). You can also know more about these built-in function by executing the statement, for example, print( help( list
) ) or print( help( str
) ). You have seen help documentation about list in previous page.
print( dir( str
) ) # This statement will show all methods of str() built-in function. (You should delete all old codes in new.py file before executing this statement!)
PS C:\xampp\
print( help( str
.capitalize ) ) # You can see all available methods of str() built-in function as shown above, and you can get help documentation of specific method by executing this statement.
Help on method_descriptor:
capitalize(self, /)
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower
case.
None
print( help( ''
.upper ) ) # You can either use keyword (e.g., str
) for which you want to get documentation, or use literal values of respective data-type. upper()
method makes all letters CAPITAL (uppercase) in a string
Help on built-in function upper:
upper() method of builtins.str instance
Return a copy of the string converted to uppercase.
None
You can get individual documentation help for each method of a specific built-in function, as you can see in above description that capitalize()
and upper()
are methods (or properties), which are applied specifically to string data-type.
print( help( ''
.count ) ) # count()
method is different from len()
built-in function. If you have already learned PHP, then you can distinguish these methods in Python with same name in PHP functions.
Help on built-in function count:
count(...) method of builtins.str instance
S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
None
print( 'Hello.count
('l') ) # outputs 4 (integer value of occurrence of l character in string 'Hello
print( len( 'Hello
bool()
, str()
, int()
, float()
, complex()
, list()
, range()
, tuple()
, dict()
, set()
, frozenset()
, bytes()
, bytearray()
, and memoryview()
built-in functions are used to create or type-cast (convert) the value assigned to a variable name in respective data-type. You have already seen in previous page some of above built-in functions, such as print()
(used to display data on the CLI or Console), exit()
and quit()
(used to quit the Python CLI), dir()
(used to show names of all methods and functions for a class/range()
and list()
(used to create an array), type()
(used to output the data-type of variable or literal).
However, there are some reserved keywords, for example, and
, as
, assert
, break
, case
, class
, continue
, del
, def
, elif
, else
, except
, False
, finally
, for
, from
, global
, if
, import
, in
, is
, lambda
, match
, None
, nonlocal
, not
, or
, pass
, raise
, return
, while
, True
, try
, etc. and different kind of operators which are frequently used in python programming language. You will learn about them in next lessons.
Leave a Comment:
Amit Sinha March 2nd, 2023 at 9:30 PM
😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😚 😋 😜 😝 😶 😏 😒 😌 😔 😪 😷 😵 😎 😲 😳 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤
Ribhu March 3rd, 2023 at 9:30 PM
🐵 🐒 🐶 🐩 🐺 🐱 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇