Prior to using Python, we need to install Python first..
Go to the authorized python website python.org, then you can find this download page :
Print(), variable initialization, input(), if
>>>print('My name is', 'Juhee')
My name is Juhee
>>>input()
Juhee is genius
'Juhee is genius'
>>>input('what is your age?: ')
what is your age?: Juhee
'Juhee'
변수 사용
>>myint=1
>>myint
1
>>>myint+1
2
>>> the_world_is_flat=True
>>> if the_world_is_flat:
print("Be careful not to fall off!!")
Be careful not to fall off!!
>>>
There are various built-in functions in Python...
We will look through all of them in order.
Let me use them and show you!
- abs(x) : Return the absolute value of number. The argument may be an integer or floating point number(there is no fixed number of digits). If the argument is a complex number, its magnitude is returned. if x defines _abs_(), abs(x) returns x._abs_().
- all(iterable) : return Ture if all elements of the iterable are true(or if the iterable is empty).
>>> def all(iterable):
for element in iterable:
if not element:
return False
return True
(def marks the start of function header.)
- any : Return True if ant element of the iterable is true. if the iterable is empty, return False.
- ascii : As repr(), return a string containint a printable representation of an object, but excape the non-ASCII characters in the string returned by repr() using \x \u or \U escapes.
- bin(x) : Convert an integer number to a binary string prefixed with "Ob".
>>> bin(3)
'0b11'
>>> bin(-10)
'-0b1010'
If prefix "0b" is not desired, then you can use the following ways.
>>> format(14,'#b'), format(14,'b')
('0b1110', '1110')
>>> f'{14:#b}', f'{14:b}'
('0b1110', '1110')
>>> format(3,'b')
'11'
>>> format(14,'b')
'1110'
Fascinating! isn't it?
Keep follow me!
- bool([x]) : Return a Boolean value, i.e. one of True or False.
- class bytearray
- class bytes([source[, encoding[, errors]]]) : Return a new "bytes" object, which is an i,,utable sequence of integers in the range 0<= x < 256.
- chr(i) : Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returnsb the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord().
- divmod(a,b) : return a pair of numbers consisting of thir quotient and remainder. result=(math.floor(a/b), a%b)
>>> divmod(9,3)
(3, 0)
- enumerate(iterable,start=0) : return an enumerate object. iterable must be a sequence.
>>> seasons=['Spring','Summer','Fall','Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons,2))
[(2, 'Spring'), (3, 'Summer'), (4, 'Fall'), (5, 'Winter')]
- eval(expression) : The expression argument is parsed and evaluated as a Python expression.
>>> x=1
>>> eval('x-2')
-1
- float(x) : Return a floating point number constructed from a number or string x.
>>> float('Infinity')
inf
>>> float('+1E6')
1000000.0
>>> float(' -12345\n')
-12345.0
>>> float('1e-003')
0.001
>>> float('nan')
nan
hex(x) : Convert an integer number to a lowercase hexadecimal string prefixed with "0x".
>>> hex(255)
'0xff'
>>> hex(-42)
'-0x2a'
>>> '%#x' % 255, '%x' % 255, '%X' % 255
('0xff', 'ff', 'FF')
>>> format(255, '#x'), format(255, 'x'), format(255,'X')
('0xff', 'ff', 'FF')
>>> f'{255:#x}', f'{255:x}', f'{255:X}'
('0xff', 'ff', 'FF')
>>>
- input([prompt]) : The function reads a line from input, converts it to a string and returns it.
>>> s = input('Enter somethin' --> ')
SyntaxError: invalid syntax
>>> s = input('Enter something---> ')
Enter something---> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"
- max(a,b,c,d) : Return the largest item in an iterable or the largest of two or more areguments.
>>> max(4,5)
5
>>> max(1,2,3,4,5)
5
- memoryview(obj) : Return a "memory view" object created from the given argument.
>>> m = memoryview(b"abc")
>>> m.tobytes()
b'abc'
>>> bytes(m)
b'abc'
>>> m.hex()
'616263'
- tolist() : Return the data in the buffer as a list of elements.
>>> memoryview(b'abc').tolist()
[97, 98, 99]
>>> import array
>>> a = array.array('d', [1.1,2.2, 3.3])
>>> m = memoryview(a)
>>> m.tolist()
[1.1, 2.2, 3.3]
- min(a, b, c, d) : Return the smallest item in an iterable or the smallest of two or more argument.
- list() : Lists are mutable(mutable object is an object whose value can change) sequences, typically used to store collections of homogeneous items.
>>> list('abc')
['a', 'b', 'c']
>>> list((1,2,4))
[1, 2, 4]
>>> list('123')
['1', '2', '3']
- range(stop) range(start, stop, step) : The arguments to the range constructor must be integers.
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(0,10,5))
[0, 5]
>>> list(range(0,10,3))
[0, 3, 6, 9]
>>> r = range(0,20,2)
>>> r
range(0, 20, 2)
>>> 11 in r
False
>>> 10 in r
True
>>> r.index(10)
5
>>> r[5]
10
>>> r[:5]
range(0, 10, 2)
>>> r[-1]
18
- str() : Return a string version of object. If object is not provided, returns the empty string.
>>> str(b'Zoot!')
"b'Zoot!'"
String Methods
- str.capitalize() : Return a copy of the string with its first character capitalized and the rest lowercase.
>>> str.capitalize("JUHEE")
'Juhee'
- str.find() : Return the lowest index in the string. Return -1 if sub is not found.
- str.format() : The string on which this method is called can contain literal text or replacement fields delimited by braces {}.
>>> "the sume of 1+2 is {0}".format(1+2)
'the sume of 1+2 is 3'
>>> 'Py' in 'Python'
True
- str.islower()
- str.isnumeric()
- str.isupper()
- str.isspace()
- str.lstrip() : Return a copy of the string with leading characters removed. default: whitespace, THe chars argument is not a prefix; rather, all combinations of its values are stripped.
>>> ' spacious '.lstrip()
'spacious '
>>> 'www.example.com'.lstrip('cmowz.')
'example.com'
>>> 'www.example.com'.lstrip('c.')
'www.example.com'
- str.replace(old,new,count) : Return a copy of the string with all occurrences of substring oldreplaced by new.
>>> 'juhee is genius and intelligent!'.replace('genius', 'silly')
'juhee is silly and intelligent!'
>>> 'mom is mom, mom'.replace('mom','juhee',3)
'juhee is juhee, juhee'
>>> 'mom is mom, mom'.replace('mom','juhee',2)
'juhee is juhee, mom'
- str.split(sep=None, maxsplit=1)
>>> '1,2,3'.split(',')
['1', '2', '3']
>>> '1,2,3'.split(',', maxsplit=1)
['1', '2,3']
>>> '1,2,,3,'.split(',')
['1', '2', '', '3', '']
>>> '1,2,3'.split(',',1)
['1', '2,3']
- str.swapcase() : Return a copy of the string with uppercase characters converted to lowercase and vice versa.
>>> s.swapcase().swapcase() ==s
True
>>> s ="juhee IS BACK"
>>> s
'juhee IS BACK'
>>> s.swapcase()
'JUHEE is back'
>>> s.swapcase().swapcase()
'juhee IS BACK'
- str.title() : Return words starting with an uppercase
Okay. these have been A LOT.. let me continue further for next page -