x, y = 1, 2
print(x, y)
x, y = y, x
print(x, y)
sentence_list = ["my", "name", "is", "George"]
sentence_string = " ".join(sentence_list)
print(sentence_string)
sentence_string = "my name is George"
sentence_string.split()
print(sentence_string)
[0]*1000
[8.2]*1000
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = {**x, **y}
name = "George"
name[::-1]
def get_a_string():
a = "George"
b = "is"
c = "cool"
return a, b, c
sentence = get_a_string()
(a, b, c) = sentence
a = [1, 2, 3]
b = [num*2 for num in a]
m = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
for key, value in m.items():
print('{0}: {1}'.format(key, value))
m = ['a', 'b', 'c', 'd']
for index, value in enumerate(m):
print('{0}: {1}'.format(index, value))
a_list = list()
a_dict = dict()
a_map = map()
a_set = set()
name = " George "
name_2 = "George///"
name.strip()
name_2.strip("/")
test = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4]
print(max(set(test), key = test.count))
import sys
x = 1
print(sys.getsizeof(x))
print(sum(range(101)))
g_var = 1
def func():
global g_var
g_var = 2
dic = {
"name": "mark lee",
"age": 19
}
del dic['age']
dic.update({
'name': 'jack ma'
})
alist = [1,1,2,2,3,4]
new_list = [val for val in set(alist)]
random.randint(min, max)
np.random.randn(5)
random.random()
print(r'\dad')
_sum = lambda a,b: a*b
print(_sum(3,4))
def s(a):
return a**2
print(list(map(s, [2, 3, 4])))
def filter_func(x):
return x % 2 == 1
alist = [1, 2, 3, 4, 5, 6, 7, 8, 9]
new_list = filter(filter_func, alist)
print([item for item in new_list])
from functools import reduce
print(reduce((lambda x, y: x * y), [1, 2, 3, 4, 5]))
s = "baaddcfee"
_s = list(set(s))
_s.sort(reverse=False)
new_s = "".join(_s)
print(new_s)
dic = {'name': 'mark', 'age': 21, 'sex': 0, 'height': 180}
sorted_dic = sorted(dic.items(), key=lambda x: x[0], reverse=False)
print(sorted_dic)
s = "abbccccdeef"
print(Counter(s)['c'])
print(type((1, )))
print(type((1)))
print(type(('1')))
list1 = [1, 3, 5]
list2 = [2, 4, 6]
list1.extend(list2)
print(list1)
_time = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + "星期" + str(datetime.datetime.now().isoweekday())
print(_time)
alist = [[1, 2], [3, 4], [5, 6]]
print([i for a in alist for i in a])
print(''.join([chr(ord(c) + 1) for c in 'abcde']))
s = 'she is 22, but he is 30'
print(re.sub(r'\d+', "25", s, count=1))
a = b"hello"
print(a)
print("你好".encode())
b'hello'
b'\xe4\xbd\xa0\xe5\xa5\xbd'
print(round(float(1.23456),2))