본문 바로가기

BackEnd/PYTHON, Django

Python Basic

반응형

Enviroment

OS : macOS mojave 10.14.2

Lang : Python 3

Editor : jupyter notebook

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#print
print(1+2)
 
#variable declaration
professor = "choi"
print(professor)
 
#for
for i in range(010):
    print(i)
 
#String
name = "홍길동"
name2 = 'Kim kildong'
 
# multi line string = like html <pre> tag
stat = '''welcome to the jungle
we have got fun and games
we got everything you want
'''
print(name)
print(name2)
print(stat)
 
#boolean
result = 10 > 20
print(result) #=> False
 
#Number and String
= 10
= 20
= 'John'
= 'Mayer'
print(a+s) #30
print(d+f) #JohnMayer
print(a,s) #10 20
print(d,f) #John Mayer
 
#Boolean Comparing
= True
print(True == 1#true
print(a == True) #true
print(True + 1#2
 
#python always do realnumber arithmetic
#Can calculate huge number immediately on high performance hardware
= 10
= 20
print(a+b, a-b, a*b, a/b) #30 -10 200 0.5
 
#square
print(2**3#8
 
#pythonic arithmetic
print(10//3)#3
print('A' * 3)#A A A
print(10%3)#0
 
#python have no increment and decrement operator**not working, but no errors**
= 1
++ a
print(a) #1
 
#python's data type is call as class
#type()
= 10
print('** type of a = ',type(a)) #<class 'int'>
 
#change data type
= float(a)
print('** type of b = ',type(b)) #<class 'float'>
= int(b)
print('** type of c = ',type(c)) #<class 'int'>
= str(c)
print('** type of d = ', type(d)) #<class 'str'>
 
#parallel operation switching value
= 1234
= 4321
 
#way on serial
temp = x
= y
= temp
print (x, y)
 
#pythonic way
x, y = y, x
print (x, y)
 
# ==, is
= 777
= 777
print(a == b, a is b)#True(Value comparing), False(address comparing)
 
# %d, %s
str = "I eat %d apples" % 3
print(str#I eat 3 apples
str = "I eat %s apples" % "Five"
print(str#I eat Five apples
 
str = "%10s" % "hi"
print(str#          hi
str = "%-10sJane" % "hi"
print(str#hi          Jane
 
#get part of string
str = 'I eat 3 apples'
print(str[0]) str.charAt(0)
print(str[ : ]) # all
print(str[ : 5]) # 0 ~ 4
print(str5 : ]) # 5 ~ last
print(str[6 : 10]) # 6 ~ 9
print(str[-1]) # last one
print(str[-8 : -1]) # -8 ~ last
 
#input function
print("입력하세요 = ", end = "")
count = input()
print("입력한 데이터 = ", count)
 
#List
colors = ['red''green''blue']
for i in colors :
    print(i)
print(len(colors))
 
datas = ['red''green', ['a','b','c']]
print(len(datas[0]))
 

 

반응형

'BackEnd > PYTHON, Django' 카테고리의 다른 글

INSTALL PACKAGES and Setting  (0) 2019.12.04
CookieCutter  (0) 2019.12.04
Parts of Django  (0) 2019.12.04
Virtual Environments  (0) 2019.12.04
Python Basic 2  (0) 2019.12.04