[PYTHON] Built-in functions

Yes. Originally there is a beautiful explanation here http://docs.python.jp/2.7/library/functions.html

Writing notes, etc. that I tried the behavior with my own hands I will add it one by one. Perhaps. .. ..

cmp(x,y) -Compares two objects x and y and returns an integer according to the result. The return value is negative when x <y, zero when x == y, and exactly positive when x> y.

cmp(x,y)


cmp(8,20)
-1
cmp(30,6)
1
cmp(15,15)
0
#x,Based on the comparison result even when either or both of y match with a negative number-1,1,The behavior of returning 0 does not change.

#Behavior when used in an if statement
print 'true' if cmp(6,10) else 'false'
true

print 'true' if cmp(18,10) else 'false'
true

print 'true' if cmp(18,18) else 'false'
false
#x,It seems that the else clause is activated only when y is equal and the return value of cmp is 0.
#true/False is 1/Not 0(Non-zero value)/Is it a judgment of 0?
#Torimayo not()Inverted? It seems that you can also let it.
print 'true' if not(cmp(18,18)) else 'false'
true

print 'true' if not(cmp(18,19)) else 'false'
false

ord

ord.py


>>> ord('a')
97
>>> ord('z')
122
>>> ord('z')
122
>>> ord('A')
65
>>> ord('Z')
90
>>> ord(90)
#Get an error
>>> ord('90')
#Get an error
>>> ord('$')
36
>>> ord('9')
57
>>> type(ord('A'))
<type 'int'> #It seems that it is returning with int

Recommended Posts

Built-in functions
Python's built-in functions
Python built-in functions ~ Zip ~
Wrap Python built-in functions
Built-in python
Python functions
Examine built-in functions (standard built-in functions) from globals
Conquer 69 Python built-in functions 6th p ~ r
Correspondence between Python built-in functions and Rust
Python built-in object
List of frequently used built-in functions and methods
Combine polynomial functions
Python built-in object
NumPy universal functions
#Python basics (functions)
[Beginner] Python functions
Python Easy-to-use functions
Useful Python built-in functions that you use occasionally
Python basics: functions