In Python, a function is a block of code that is defined once and can be executed multiple times. Functions are a way to organize and reuse code, and they are an important part of the Python programming language.
To define a function in Python, you use the def keyword, followed by the name of the function and a pair of parentheses. The parentheses can contain parameters, which are variables that represent the input to the function.
For example:
Copy codedef greet(name):
print("Hello, " + name)
This function, called greet, takes a single parameter called name and prints a greeting using the value of name. To call a function, you use the name of the function followed by a pair of parentheses, and you can pass in any arguments that the function is expecting.
For example:
Copy codegreet("John") # prints "Hello, John"
greet("Jane") # prints "Hello, Jane"
Functions can also return a value to the caller by using the return statement.
For example:
Copy codedef add(x, y):
return x + y
result = add(3, 4) # result is 7
Functions can be defined anywhere in a Python program, but they are usually defined at the beginning of a file or after any other functions they depend on. Functions can also be defined inside other functions, in which case they are called nested functions.
List of all Built-in Python Functions
Function | Description |
Abs() | returns absolute value of a number |
All() | returns true when all elements in iterable is true |
Any() | checks if any element of iterable is true |
Ascii() | returns string containing printable representation |
Bin() | converts integer to binary string |
Bool() | converts a value to Boolean |
Bytearray() | returns array of given byte size |
Bytes() | returns immutable bytes object |
Callable() | checks if the object is callable |
Chr() | returns a character(a string)from an integer |
Classmethod() | returns class method for given function |
Compile() | returns a python code object |
Complex() | creates a complex number |
Delatrr() | deletes attribute from the object |
Dir() | tries to return attributes of object |
Divmod() | returns a tuple of quotient and remainder |
Enumerate() | returns a enumerate object |
Eval() | runs python code within program |
Exec() | executes dynamically created program |
Filter() | constructs iterator from elements which are true |
Float() | returns floating point number from number, string |
Format() | returns formatted representation of a value |
Getattr() | returns value of named attribute of an object |
Globals() | returns dictionary of current global symbol table |
Hasattr() | returns whether object has named attribute |
Hash() | returns hash value of an object |
Help() | invokes the built-in help system |
Hex() | converts to integer to hexadecimal |
Id() | returns identify of an object |
Isinstance() | checks if a object is an instance of class |
Issubclass() | checks if a object is subclass of a class |
Iter() | returns iterator of an object |
Len() | returns length of an object |
Locals() | returns dictionary of a current local symbol table |
Map() | applies function and returns a list |
Max() | returns largest element |
Memoryview() | returns memory view of an argument |
Min() | returns smallest element |
Next() | retrieves next element from iterator |
Object() | creates a featureless object |
Oct() | converts integer to locals |
Open() | returns a file object |
Ord() | returns Unicode code for Unicode character |
Pow() | returns x to the power of y |
Print() | prints the given object |
Property() | returns a property attribute |
Range() | returns sequence of integers between start and stop |
Repr() | returns printable representation of an object |
Reversed() | returns reversed iterator of a sequence |
Round() | rounds a floating point number to n digits places |
Set() | returns a python set |
Setattr() | sets value of an attribute of object |
Slice() | creates a slice object specified by range |
Sorted() | returns sorted list from a given iterable |
Staticmethod() | creates a static method from a function |
Str() | returns informal representation of an objects |
Sum() | add items of an iterable |
Super() | allow you to prefer parent class by super |
Type() | returns type of an object |
Vars() | returns_ dict _ attribute of a class |
_import_() | advanced function called by import |
STRING FUNCTIONS
Function | Description |
Capitalize() | converts first character to capital letter |
Casefold() | converts to casefolded strings |
Center() | pads string with specified character |
Count() | returns occurrences of substring in string |
Encode() | returns encoded string of given string |
Endswith() | checks if string ends with the specified suffix |
Expandtabs() | returns tab character with spaces |
Find() | returns index of substring |
Format() | formats the string using dictionary |
Format_map() | formats the string using dictionary |
Index() | returns index of substring |
Input() | reads and returns a line of string |
Int() | returns integer from a number or string |
Isalnum() | checks alphanumeric character |
Isalpha() | checks if all characters are alphabets |
Isdecimal() | checks decimal characters |
Isdigit() | checks digit characters |
Isidentifier() | checks for valid identifiers |
Islower() | checks if all alphabets in a string are lowercase |
Isnumeric() | checks numeric characters |
Isprintable() | checks printable characters |
Isspace() | checks whitespace characters |
Istitle() | checks for titlecased string |
Isupper() | returns if all characters are uppercase characters |
Join() | returns s concatenated string |
Ljust() | returns left _ justified string of given width |
Lower() | returns lowercased string |
Lstrip() | removes leading characters |
Maketrans() | returns a translation table |
Partition() | returns a tuple |
Replace() | replaces substring inside |
Rfind() | returns the highest index of substring |
Rindex() | returns highest index of substring |
Rjust() | returns right-justified string of given width |
Rpartition() | returns a tuple |
Rsplit() | splits string from right |
Rstrip() | removes trailing characters |
Slice() | creates a slice object specified by range() |
Split() | splits string from left |
Splitlines() | splits string at line boundaries |
Startswith() | checks if string starts with the specified string |
Strip() | removes both leading and trailing characters |
Swapcase() | swap uppercase characters to lowercase; vice versa |
Title() | returns a title cased string |
Translate() | returns mapped character string |
Upper() | returns uppercased string |
Zfill() | returns a copy of the string padded with zeros |
LIST FUNCTIONS
Function | Description |
Append() | add single element to the list |
Clear() | removes all items from the lists |
Copy() | returns shallow copy of a list |
Count() | returns occurrences of element in a list |
Extend() | add element of a list to another list |
Index() | returns smallest index of element in list |
Insert() | inserts element to the list |
List() | creates list in python |
Pop() | removes element at given index |
Remove() | removes element from the list |
Reverse() | reverses a list |
Slice() | creates a slice object specified by range() |
Sort() | sorts elements of a list |
TUPLE FUNCTIONS
Function | Description |
Count() | returns occurrences of element in a tuple |
Index() | returns smallest index of element in tuple |
Slice() | creates a slice object specified by range() |
Tuple() | creates a tuple |
Zip() | returns an iterator of tuples |
SET FUNCTIONS
Function | Description |
Add() | adds element to a set |
Clear() | removes all elements from a set |
Copy() | returns shallow copy of a set |
Difference() | returns difference of two sets |
Difference_update() | updates calling set with intersections of sets |
Discard() | removes an element from the set |
Frozenset() | returns immutable frozenset object |
Intersection() | returns intersection of two or more sets |
Intersection_update() | updates calling set with intersection of sets |
Isdisjoint() | checks disjoint sets |
Issubset() | checks if a set is subset of another set |
Issuperset() | checks if a set is superset of another set |
Pop() | removes an arbitrary element |
Remove() | removes element from the set |
Set() | returns a python set |
symmetric_difference() | returns symmetric sdifference |
symmetric_difference_update() | updates set with symmetric difference |
union() | returns union of sets |
update() | add elements to the set |
DICTIONARY FUNCTIONS
Function | Description |
Clear() | removes all items |
Copy() | returns shallow copy of a dictionary |
Dict() | creates a dictionary |
Fromkeys() | creates dictionary from given sequence |
Get() | returns value of the key |
Items() | returns view of dictionary’s(key, value) pair |
Keys() | returns view object of all keys |
Pop() | removes and returns element having given key |
Popitem() | returns & removes element from dictionary |
Setdefault() | inserts key with a value if key is not present |
Update() | updates the dictionary |
Values() | returns view of all values in dictionary |
Namaste-thanks-Any chance you will clear up some misconceptions?
Thanks for your support bro.
a lot of vape juice
Thanks for your valuable feedback bro and keep supporting us.
My spouse and I absolutely love your blog and find most of your post’s to be precisely what I’m looking for. Do you offer guest writers to write content in your case? I wouldn’t mind composing a post or elaborating on many of the subjects you write with regards to here. Again, awesome web site!
Hi there, I enjoy reading through your article post. I wanted
to write a little comment to support you.
I keep listening to the news update speak about receiving boundless online grant applications so I have been looking around for the top site to get one. Could you advise me please, where could i acquire some?
Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how can we communicate?
Hello there, just became aware of your blog through Google, and found that it’s really informative. I am going to watch out for brussels. I抣l appreciate if you continue this in future. Numerous people will be benefited from your writing. Cheers!
you’re really a good webmaster. The web site loading speed is incredible. It kind of feels that you are doing any unique trick. In addition, The contents are masterwork. you have done a excellent job in this topic!
Thanks for the recommendations you have provided here. Something important I would like to talk about is that pc memory needs generally increase along with other breakthroughs in the engineering. For instance, any time new generations of cpus are brought to the market, there is certainly usually a related increase in the type calls for of both personal computer memory and hard drive space. This is because the software program operated by simply these processor chips will inevitably increase in power to benefit from the new engineering.
I really like what you guys are up too. This type of clever work and reporting! Keep up the good works guys I’ve you guys to my own blogroll.
Hello.This post was extremely fascinating, particularly since I was searching for thoughts on this issue last couple of days.
It’s best to participate in a contest for one of the best blogs on the web. I’ll recommend this web site!
I have learn a few good stuff here. Certainly price bookmarking for revisiting. I surprise how so much attempt you set to create this sort of magnificent informative site.
What I have seen in terms of laptop or computer memory is always that there are features such as SDRAM, DDR and so forth, that must fit the specs of the mother board. If the personal computer’s motherboard is kind of current and there are no main system issues, updating the memory space literally usually takes under an hour. It’s among the easiest pc upgrade treatments one can imagine. Thanks for spreading your ideas.
Best view i have ever seen !
It is really a nice and useful piece of information. I am glad that you shared this useful info with us. Please keep us informed like this. Thank you for sharing.
Thanks for the points you have discussed here. Something else I would like to state is that pc memory specifications generally rise along with other breakthroughs in the technological know-how. For instance, any time new generations of processor chips are brought to the market, there is usually a related increase in the size and style demands of both the pc memory in addition to hard drive space. This is because the software operated simply by these processor chips will inevitably increase in power to take advantage of the new technology.
Hello! I’m at work surfing around your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the superb work!
Good stuff!
I constantly spent my half an hour to read this web site’s
articles everyday along with a cup of coffee.
This page really has all of the information I wanted about this subject and didn’t know who to ask.
Hi! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely delighted I found it and I’ll be book-marking and checking back often!
Hello there, You’ve done an incredible job. I’ll certainly digg it and personally suggest to my friends. I am confident they’ll be benefited from this website.
Hi there, I found your blog via Google while searching for a similar matter, your website came up, it looks good. I’ve bookmarked it in my google bookmarks.
I simply want to tell you that I am very new to blogs and really enjoyed you’re blog. Likely I’m planning to bookmark your blog . You surely have wonderful articles and reviews. Thanks a lot for sharing with us your website.
I am sure this post has touched all the internet people, its really really good piece of writing on building
up new web site.
It is appropriate time to make a few plans for the
longer term and it is time to be happy. I’ve learn this
publish and if I may I desire to suggest you few fascinating things or suggestions.
Maybe you could write subsequent articles relating to this article.
I wish to learn more things approximately it!
Wow! At last I got a blog from where I be capable of actually get useful
data regarding my study and knowledge.
Ahaa, its pleasant conversation on the topic of this article
here at this website, I have read all that, so
now me also commenting here.
Hello! I’ve been reading your website for some time now and finally got the bravery to go ahead and give you a
shout out from Austin Tx! Just wanted to say keep up
the fantastic job!