Skip to content
Snippets Groups Projects
Commit 38464869 authored by Joo byeong jin's avatar Joo byeong jin
Browse files

기말준비

parent 2ac90bd9
No related branches found
No related tags found
No related merge requests found
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> b="""hello.
world.
"""
>>> b
'hello.\nworld.\n'
>>> type(b)
<class 'str'>
>>> a="hello"
>>> a
'hello'
>>> a='hello'
>>> a
'hello'
>>> a+b
'hellohello.\nworld.\n'
>>> a*4
'hellohellohellohello'
>>> # 문자열은 '+,*' 가능.
>>>
>>> s='good morning'
>>> s[0]
'g'
>>> s[0:4]
'good'
>>> 'sdasd' in s
False
>>> len(s)
12
>>> c='\n\n\n'
>>> c
'\n\n\n'
>>> len(c)
3
>>> c='\\n\\n\\n'
>>> c
'\\n\\n\\n'
>>> len(c)
6
>>> b='1234'
>>> b.isnumeric()
True
>>> b=-2
>>> bin(b)
'-0b10'
>>> b
-2
>>> 9&10
8
>>> 9^10
3
>>> ## &는 논리 곱으로 둘다 1인경우만 1로 표현된다.
44 +>>> ## 9 = 1001
45 +>>> ## 10= 1010
46 +>>> ## 8 = 1000
SyntaxError: invalid character in identifier
>>>
>>> >>> ## ^는 배타적 논리합 으로 둘다 다른 경우만 1이다.
51 +>>> ## 9 = 1001
52 +>>> ## 10= 1010
53 +>>> ## 3 = 0011
SyntaxError: invalid syntax
>>>
>>> a=255
>>> ~a
-256
>>> a
255
>>> ## 비트연산자 ~ 는 이진수표현에서 0을 1로, 1을 0으로 뒤집고 -1을 한값이다.
>>>
>>> a=2340
>>> ~a
-2341
>>> bin(a)
'0b100100100100'
>>> bin(~a)
'-0b100100100101'
>>> a=76
>>> bin(a)
'0b1001100'
>>> 9|10
11
>>> a=15
>>> bin(15)
'0b1111'
>>> bin(15&0b1011)
'0b1011'
>>> ~a
-16
>>> a= ['가나다','마바사','123']
>>> [0]
Traceback (most recent call last):
File "<pyshell#52>", line 1, in <module>
[0]
NameError: name '' is not defined
>>> a[0]
'가나다'
>>> ## 리스트에는 숫자와 문자열을 같이 넣을수 있다.
>>>
>>> a=[1,2,3,4,5,6,7,8,9,10]
>>> a[0:5]
[1, 2, 3, 4, 5]
>>> a[8:]
[9, 10]
>>> a= ['가나다','마바사','123']
>>> len(a)
3
>>> a[2]
'123'
>>> a=[1,2,3,4,5,6,7,8,9,10]
>>> a[4]=11
>>> a
[1, 2, 3, 4, 11, 6, 7, 8, 9, 10]
>>> a=[1,2,3,12,123,234124,23]
>>> a.sort()
>>>
>>> a
[1, 2, 3, 12, 23, 123, 234124]
>>> #오름차순 정렬
>>>
>>>
>>>
>>>
>>>
>>> a=(1,2,3)
>>> a[0]
1
>>> a[0]=4
Traceback (most recent call last):
File "<pyshell#77>", line 1, in <module>
a[0]=4
TypeError: 'tuple' object does not support item assignment
>>> ## 튜플 - 변경이 불가능한 자료형.( 문자열도 변경x )
>>>
>>> a=1
>>> a
1
>>> type(a)
<class 'int'>
>>> a=1,
>>> a
(1,)
>>> type(a)
<class 'tuple'>
>>> ## 요소가 하나인 경우에는 , 를 반드시 추가.
>>>
>>> a=-4
>>> b=51
>>> a&b
48
>>> 0b110000
48
>>> a|b
-1
>>> a
-4
>>>
>>>
>>> >>> ## index 함수는 몇번째에 성분이있는지 찾아주는함수.
52 +>>> a=1,2,3
53 +>>> a
54 +(1, 2, 3)
55 +>>> a.index(2)
56 +1
57 +>>>
SyntaxError: invalid syntax
>>>
>>> bin(-1)
'-0b1'
>>> bin(-5)
'-0b101'
>>> bin(51)
'0b110011'
>>> -5|51
-5
>>> -5&51
51
>>> ~1
-2
>>> dic['파이썬']="ㅈㅈㅈㅈ"
Traceback (most recent call last):
File "<pyshell#104>", line 1, in <module>
dic['파이썬']="ㅈㅈㅈㅈ"
NameError: name 'dic' is not defined
>>> dic={}
>>> dic['파이썬']="ㅈㅈㅈㅈ"
>>> 파이썬
Traceback (most recent call last):
File "<pyshell#107>", line 1, in <module>
파이썬
NameError: name '파이썬' is not defined
>>> dic['파이썬']
'ㅈㅈㅈㅈ'
>>> '파이썬'in dic.keys()
True
>>>
>>> b=([1,2,3],[4,5,6])
>>>
>>> b
([1, 2, 3], [4, 5, 6])
>>> b[0]
[1, 2, 3]
>>> b[0][0]=9
>>> b
([9, 2, 3], [4, 5, 6])
>>> 0xffff
65535
>>> a=3>2
>>> a
True
>>> type(a)
<class 'bool'>
>>> ## bool값에서는 0 을 제외한 모든 값이 참이다.
>>>
>>>
>>> >>> ## continue 와 break 의 차이점
4 +>>> ## break는 조건이만족되면 함수중단.
5 +>>> ## continue는 조건이만족되면, 다시 조건문으로 올라간다.
SyntaxError: invalid syntax
>>> for i in range(10):
if i % 2 == 1:
continue
print(i)
0
2
4
6
8
>>> for i in range(10):
if i % 2 == 1:
break
print(i)
0
>>> a=100
>>> def local_test():
a=200
print(a)
>>> a
100
>>> local_test()
200
>>> a
100
>>> ## 함수안에서 사용되는 변수는 값이 한번 사용되고 값이 사라진다.
>>>
>>>
>>> def local_test():
global a
a=200
print(a)
>>> local_test()
200
>>> a
200
>>> 0xf0
240
>>> 16*15
240
>>> a= 2+3j
>>> a
(2+3j)
>>> type(a)
<class 'complex'>
>>>
>>>
>>> import math
>>> math.pi
3.141592653589793
>>> a=(1,2,3,4,5,6)
>>> a[:3]
(1, 2, 3)
>>> a[0]
1
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment