머신러닝 프로그래밍 2주차
print("hello world!","m","a","v","c",sep="-----")
hello world!-----m-----a-----v-----c
print("hello world!","m","a","v","c",sep=".",end="\n\n\n")
hello world!.m.a.v.c
help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"dddd".endswith("d")
True
float("1234.33")
1234.33
"11233".isnumeric() #문자열이 숫자로 구성되어 있는지 확인해주는 함수
True
10**2
100
2.2**22
34142787.73642202
9/2
4.5
9//2
4
9-2
7
"A"+"b"
'Ab'
"a"*3
'aaa'
"-+"*2
'-+-+'
'sd>>"hello"<<ff'
'sd>>"hello"<<ff'
"aaaaaaa".upper()
'AAAAAAA'
"TTTTT".lower()
'ttttt'
"asadadas.wwww".capitalize() #문자열의 첫글자는 대문자로, 나머지는 소문자로 변환한다.
'Asadadas.wwww'
"asddwd.DDD".find(".")
6
"asdasd".rfind("s")#뒤에서 찾기
4
"WFWQFSA".lower().rfind("S")
-1
"WF" in "WFAWSDW"
True
"wDADASD".__len__()
7
"wDADASD"
'wDADASD'
len("asdasdsa")
8
#tuple
(1,2,3,4,5) #튜플은 변경불가능, 리스트는 변경가능(추가가능)
(1, 2, 3, 4, 5)
(1,2,3,4,5,["assdsad"])
(1, 2, 3, 4, 5, ['assdsad'])
[1,2,3,4,5,"ddd",[123123]] #list
[1, 2, 3, 4, 5, 'ddd', [123123]]
a =1
print(a)
1
b="Asdassds"
print(b)
Asdassds
a=["Asdsada",123]
a
['Asdsada', 123]
n=0
for i in range(1,10):
print(i)
i += 1
1
2
3
4
5
6
7
8
9
a = [1,3,4,5]
a[-4]
1
len(a)
4
a[a[0]]
3
a =[12,33,44]
a[-1]=[3,4]
a
[12, 33, [3, 4]]
# a.sort()
a.reverse()
a
[[3, 4], 33, 12]
list(reversed(a))[0]
12
a[0:3]
[[3, 4], 33, 12]
help([])
Help on list object:
class list(object)
| list(iterable=(), /)
|
| Built-in mutable sequence.
|
| If no argument is given, the constructor creates a new empty list.
| The argument must be an iterable if specified.
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(self, /)
| Return a reverse iterator over the list.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(self, /)
| Return the size of the list in memory, in bytes.
|
| append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse *IN PLACE*.
|
| sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
| order of two equal elements is maintained).
|
| If a key function is given, apply it once to each list item and sort them,
| ascending or descending, according to their function values.
|
| The reverse flag can be set to sort in descending order.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
l = [1,2,3,4]
t = [3,4,5,6]
l[0]
1
t[0]
3
l[0] = 5
l
[5, 2, 3, 4]
t =list(t)
t= tuple(t)
t
(3, 4, 5, 6)
l.append(11111)
l
[5, 2, 3, 4, 11111]
l.append("ss")
l
[5, 2, 3, 4, 11111, 'ss']
l = l + [333]
l
[5, 2, 3, 4, 11111, 'ss', 333]
l +l
[5, 2, 3, 4, 11111, 'ss', 333, 5, 2, 3, 4, 11111, 'ss', 333]
[1,2]*10
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
(1,2)*10
(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
"-"*10
'----------'
if True:
print("tt")
tt
if False:
print("false")
if 1 <2:
print(2)
2
if l[0] <100:
print("sdsd")
l[0] = l[0]*10
sdsd
l
[50, 2, 3, 4, 11111, 'ss', 333]
if l[0] <100:
print("sdsd")
l[0] = l[0]*10
else:
print("ASd")
sdsd
l
[500, 2, 3, 4, 11111, 'ss', 333]
l
[500, 2, 3, 4, 11111, 'ss', 333]
if l[0] <100:
print("sdsd")
l[0] = l[0]*10
else:
if l[1]<1111:
print("asdas")
print("ASd")
asdas
ASd
l
[500, 2, 3, 4, 11111, 'ss', 333]
if l[0] <100:
print("sdsd")
l[0] = l[0]*10
elif l[1] >100:
pass
else:
if l[1]<1111:
print("asdas")
print("ASd")
asdas
ASd
s = 0
for i in 1,2,3,4,5:
s = s + i
print(s)
15
s = 0
for i in range(11):
s = s + i
print(s)
55
help(range)
Help on class range in module builtins:
class range(object)
| range(stop) -> range object
| range(start, stop[, step]) -> range object
|
| Return an object that produces a sequence of integers from start (inclusive)
| to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.
| start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.
| These are exactly the valid indices for a list of 4 elements.
| When step is given, it specifies the increment (or decrement).
|
| Methods defined here:
|
| __bool__(self, /)
| self != 0
|
| __contains__(self, key, /)
| Return key in self.
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(...)
| Return a reverse iterator.
|
| count(...)
| rangeobject.count(value) -> integer -- return number of occurrences of value
|
| index(...)
| rangeobject.index(value) -> integer -- return index of value.
| Raise ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| start
|
| step
|
| stop
s = 0
for i in range(1,11,2):#2칸씩 띄어써
s = s + i
print(s)
25
s = 0
for i in range(10,0,-2):#2칸씩 띄어써
print(s,i)
s = s + i
print(s)
0 10
10 8
18 6
24 4
28 2
30
s = 1
for i in range(3,10,3):
print("mul:",s,"*",i)
s = s * i
print(s)
mul: 1 * 3
mul: 3 * 6
mul: 18 * 9
162
s = 1
for i in range(1,51):
if i % 3 == 0:
print("mul:",s,"*",i)
s = s * i
print(s)
mul: 1 * 3
mul: 3 * 6
mul: 18 * 9
mul: 162 * 12
mul: 1944 * 15
mul: 29160 * 18
mul: 524880 * 21
mul: 11022480 * 24
mul: 264539520 * 27
mul: 7142567040 * 30
mul: 214277011200 * 33
mul: 7071141369600 * 36
mul: 254561089305600 * 39
mul: 9927882482918400 * 42
mul: 416971064282572800 * 45
mul: 18763697892715776000 * 48
900657498850357248000