Uday_codes_python_3
Uday_codes_python_3
Name Usage
print() Function prints the message to the screen or any other standard output device.
round(number, Rounds the float value to the given number of decimal digits.
digits(optional))
set(sequence) Takes any sequence as argument and converts to set, avoiding duplicates.
min() Returns the smallest item in a sequence or the smallest of two or more arguments.
max() Returns the largest item in a sequence or the largest of two or more arguments.
sorted(sequence) Returns a new sequence with all the items in the given sequence ordered in increasing
order.
sorted(sequence, Returns a new sequence with all the items in the given sequence ordered in
reverse=True) decreasing order.
map() Applies a given function to each item of a sequence (list, tuple etc.) and returns a
sequence of the results.
filter() Method filters the given sequence with the help of a function that tests each element
in the sequence to be true or not.
reduce() Receives two arguments, a function and an iterable. However, it doesn't return another
iterable, instead, it returns a single value.
Floating Point Errors : Sometimes, floating point approximation gives unexpected results.
print((0.1 + 0.2) == 0.3) # False
a = 10
a -= 2
print(a) # 8
a = 10
a /= 2
print(a) # 5.0
a = 10
a %= 2
print(a) # 0
Single And Double Quotes : A string is a sequence of characters enclosed within quotes.
sport = 'Cricket'
sport = "Cricket"
Escape Characters : Escape Characters are a sequence of characters in a string that is interpreted differently by the
computer. We use escape characters to insert characters that are illegal in a string.
print("Hello\nWorld" )
# Output is:
Hello
World
Name Usage
\n New Line
\t Tab Space
\\ Backslash
Set Methods :
update() set.update(sequence) Adds multiple items to the set, and duplicates are avoided.
Immutable Items : Set items must be immutable. As List is mutable, Set cannot have list as an item.
set_a = {"a", ["c", "a"]}
print(set_a ) # TypeError: unhashable type: 'list'
Dictionary Views :
Dictionary Methods :