tmp.py
#variable
s = "str..."
l = ["1", "2", "3", "3", "4"]
t = ("A", "B", "C")
d = {"key": "value"}
s_ = str("str")
i_ = int("99")
f_ = float("100.0")
l_ = list((1,2,3))
d_ = dict([["key, "value"]])
e = set("0123456789")
ss = '''
dup
dup
dup
'''
#Print syntax
print(s, end="")
#slice
s[0:1]
s[-1]
s[::1]
#Built-in functions
len(s)
s.split()
",".join(l)
s.strip(".")
s.capitalize()
s.title()
s.upper()
s.lower()
s.swapcase()
s.replace(".", "!")
l.append("5")
l.insert(0, "10")
del l[0]
l.remove("10")
l.pop()
l.index("1")
l.count("3")
l.sort()
c = l.copy()
d.keys()
d.values()
d.items()
#for loop
for val in l:
print(val)
#Calculation
False | True
True & True
1 > 0
0 >= 0
#if statement
if s == "s":
print("s!")
elif s == "str":
print("str!")
else:
print("!!!")
#while loop
count = 0
while count < 3:
print(count)
count += 1
while True:
print(count)
if count == 5:
break
count += 1
#List comprehension
ll = [v for v in range(10)]
#function
def f(a,b):
return a+b
#class
class S():
def __init__(self, a, b):
self.a = a
self.b = b
def rep():
print(self.a + " " + self.b)
ss = S("Thank", "you")
ss.rep()
Recommended Posts