百度架构师手把手带你零基础实践深度学习(1)

作业
1.百度架构师手把手带你零基础实践深度学习(1)_第1张图片2.

for i in range(1, 10):
    for j in range(1, i+1):
        print("%d*%d = %d  " % (j, i, i * j), end="  ")  #乘法
        if j == i:
            print()  #换行
        j += 1
    i += 1

学习Python代码记录(学习中)

ab@ab-Lenovo-Legion-Y7000-2020:~$ python
Python 2.7.17 (default, Jul 20 2020, 15:37:01) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> ran = random.random()
>>> print(ran)
0.0581298524481
>>> ran = random.random(1,20)
Traceback (most recent call last):
  File "", line 1, in <module>
TypeError: random() takes no arguments (2 given)
>>> ran = random.random(1,20)
Traceback (most recent call last):
  File "", line 1, in <module>
TypeError: random() takes no arguments (2 given)
>>> ran = random.randint(1,20)
>>> print()ran
  File "", line 1
    print()ran
             ^
SyntaxError: invalid syntax
>>> print(ran)
11
>>> print("----------设置种子-----------------")
----------设置种子-----------------
>>> random.seed(10)
>>> print("Random number with seed 10 : ",random.random)
('Random number with seed 10 : ', <built-in method random of Random object at 0x557d61753e20>)
>>> print("Random number with seed 10 : ",random.random())
('Random number with seed 10 : ', 0.5714025946899135)
>>> random.seed(10)
>>> print("Random number with seed 10 : ",random.random())
('Random number with seed 10 : ', 0.5714025946899135)
>>> print("hello world")
hello world
>>> print('hello world')
hello world
>>> print('hello wor\tld')
hello wor	ld
>>> str1 = "hello "
>>> str2 = "world"
>>> print(str1 + str2)
hello world
>>> names = ['jack','tom','tonney','superman','jay']
>>> print(names[0])
jack
>>> print(names[-1])
jay
>>> print(names[len(names)-1])
jay
>>> 
>>> for name in names:#注意对齐
...     if name == 'superman':
...             print('有超人')
...             break;
... else:
...     print('无超人')
... 
有超人
>>> girls = []
>>> girls.append('杨超越')
>>> print(girls)
['杨超越']
>>> models = ['刘雯','贾玲']
>>> girls.extend(models)
>>> print(girls)
['杨超越', '刘雯', '贾玲']
>>> girls.insert(1,'邓紫棋')
>>> print(girls)
['杨超越', '邓紫棋', '刘雯', '贾玲']
>>> girls[-1] = '赵丽颖'
>>> print(girls)
['杨超越', '邓紫棋', '刘雯', '赵丽颖']
>>> for i in range(len(girls)):
...     if '刘雯' in girls[i]:
...             girls[i] = '杨幂'
...             break
... 
>>> print(girls)
['杨超越', '邓紫棋', '杨幂', '赵丽颖']
>>> del girls[1]
>>> print(girls)
['杨超越', '杨幂', '赵丽颖']
>>> girls.remove('杨超越')
>>> print(girls)
['杨幂', '赵丽颖']
>>> print(girls[0:2])
['杨超越', '邓紫棋']
>>> import random
>>> random_list = []
>>> i = 0
>>> while i < 10:
...     ran = random.randint(1,20)
...     if ran not in random_list:
...             random_list.append(ran)
...             i+=1
... 
>>> print(random_list)
[11, 13, 19, 1, 7, 2, 16, 20, 4, 12]
>>> #默认升序
... new_list = sorted(random_list)
>>> print(new_list)
[1, 2, 4, 7, 11, 12, 13, 16, 19, 20]
>>> #降序
... new_list = sorted(random_list,reverse = True)
>>> print(new_list)
[20, 19, 16, 13, 12, 11, 7, 4, 2, 1]
>>> tuple1 = ()#元组
>>> print(type(tuple1))
<class 'tuple'>
>>> tuple2 = ('hello')
>>> print(type(tuple2))
<class 'str'>
>>> tuple3 = ('hello',)
>>> print(type(tuple3))
<class 'tuple'>
>>> import random
>>> random_list = []
>>> for i in range(10):
...     ran = random.randint(1,20)
...     random_list.append(ran)
... 
>>> print(random_list)
[10, 19, 9, 2, 11, 19, 11, 20, 14, 10]
>>> random_tuple = tuple(random_list)
>>> print(random_tuple)
(10, 19, 9, 2, 11, 19, 11, 20, 14, 10)
>>> t3 = (1,2,3)
>>> a,b,c = t3
>>> print(a,b,c)
1 2 3
>>> t5 = (1,2,3,4,5)
>>> a,b,*c = t5
>>> print(a,b,c)
1 2 [3, 4, 5]
>>> print(c)
[3, 4, 5]
>>> 

>>> #字典
... dict1 = {}
>>> dict2 = {'name':'贾玲','weight':55,'age':35}
>>> print(dict2['name'])
贾玲
>>> dict4 = {}
>>> dict4['name'] = '杨幂'
>>> dict4['weight'] = 43
>>> print(dict4)
{'name': '杨幂', 'weight': 43}
>>> dict4['weight'] = 45
>>> print(dict4)
{'name': '杨幂', 'weight': 45}
>>> dict5 = {'杨超越':165,'贾玲':166,'杨幂':164}
>>> print(dict5.items())
dict_items([('杨超越', 165), ('贾玲', 166), ('杨幂', 164)])
>>> for key,value in dict5.items():
...     if value > 165:
...             print(key)
... 
贾玲
>>> names = dict5.keys()
>>> print(names)
dict_keys(['杨超越', '贾玲', '杨幂'])
>>> heights = dict5.values()
>>> print(he)
heights  help(    hex(     
>>> print(heights)
dict_values([165, 166, 164])
>>> total = sum(heights)
>>> avg = total/len(heights)
>>> print(avg)
165.0

>>> dict6 = {'杨超越':165,'贾玲':166,'杨幂':164}
>>> del dict6['杨超越']
>>> print(dict6)
{'贾玲': 166, '杨幂': 164}
>>> class Animal:#类
...     def __init__(self,name):
...             self.name = name
...             print('动物名称实例化')
...     def eat(self):
...             print(self.name + '吃东西')
...     def drink(self):
...             print(self.name + '喝水呀')
... 
>>> cat = Animal('miaomiao')
动物名称实例化
>>> print(cat.name)
miaomiao
>>> cat.eat()
miaomiao吃东西
>>> cat.drink()
miaomiao喝水呀
>>> class Person:
...     def __init__(self,name):
...             self.name = name
...             print('调用父类构造函数')
...     def eat(self):
...             print('调用父类的方法')
... 
>>> class Student(Person):
...     def __init__(self):
...             print('调用子类构造函数')
...     def study(self):
...             print('调用子类的方法')
... 
>>> s = Student()
调用子类构造函数
>>> s.study()
调用子类的方法
>>> s.eat()
调用父类的方法
>>>

你可能感兴趣的:(笔记,深度学习,python)