Python1

简介:
anaconda3下载地址
    官网:https://www.anaconda.com/download/
    百度云链接:https://pan.baidu.com/s/17jHeU909P1pmITCkZg3tcQ 密码:javt
    
python基础语法文档
    官网:https://docs.python.org/3.6/tutorial/index.html
    
为什么要使用python
    一、python调试非常简单的解释性语言
    二、跨平台
    三、广泛的应用编程接口
    四、丰富的开源包
    
Python编辑器下载:https://www.jetbrains.com/pycharm/
破解介绍(该网址注册码已过期):https://blog.csdn.net/px41834/article/details/79256024/
注册码:

K71U8DBPNE-eyJsaWNlbnNlSWQiOiJLNzFVOERCUE5FIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBlZHVjYXRpb25hbCB1c2Ugb25seSIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3RzIjpbeyJjb2RlIjoiSUkiLCJwYWlkVXBUbyI6IjIwMTktMDUtMDQifSx7ImNvZGUiOiJSUzAiLCJwYWlkVXBUbyI6IjIwMTktMDUtMDQifSx7ImNvZGUiOiJXUyIsInBhaWRVcFRvIjoiMjAxOS0wNS0wNCJ9LHsiY29kZSI6IlJEIiwicGFpZFVwVG8iOiIyMDE5LTA1LTA0In0seyJjb2RlIjoiUkMiLCJwYWlkVXBUbyI6IjIwMTktMDUtMDQifSx7ImNvZGUiOiJEQyIsInBhaWRVcFRvIjoiMjAxOS0wNS0wNCJ9LHsiY29kZSI6IkRCIiwicGFpZFVwVG8iOiIyMDE5LTA1LTA0In0seyJjb2RlIjoiUk0iLCJwYWlkVXBUbyI6IjIwMTktMDUtMDQifSx7ImNvZGUiOiJETSIsInBhaWRVcFRvIjoiMjAxOS0wNS0wNCJ9LHsiY29kZSI6IkFDIiwicGFpZFVwVG8iOiIyMDE5LTA1LTA0In0seyJjb2RlIjoiRFBOIiwicGFpZFVwVG8iOiIyMDE5LTA1LTA0In0seyJjb2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ggrWjV8GYpw5bq23VmIqqDLgkNzuoog==

Python常用命令介绍:

#!/usr/bin/pyhon3
#if条件语句
# x = int(input("Please enter an integer: "))
# if x < 0:
#     x = 0
#     print('Negative changed to zero')
# elif x == 0:
#     print('Zero')
# elif x == 1:
#     print("single")
# else:
#     print('More')

#for循环语句
words = ['cat', 'window', 'defenestrate']
for w in words:
    print(w, len(w))

#range()函数
print(range(5))
#[0, 1, 2, 3, 4]
print(list(range(5)))
for i in range(5):
    print(i)
#range的等差数列
print(list(range(0, 10, 3)))
print(list(range(-10, -100, -30)))
#取10以内的质数的程序
for n in range(2, 10):
     for x in range(2, n):
        if n % x == 0:
            print(n, 'equals', x, '*', n//x)
            break
     else:
            # loop fell through without finding a factor
        print(n, 'is a prime number')

#定义一个函数  计算斐波那契额
#把我们重复的计算劳动封装成一个函数,来减少工作
#def关键字是定义函数的,后面必须跟着函数名和包括形式参数的圆括号,
#它的下一行必须是缩进
def fib(n):    # write Fibonacci series up to n
     """Print a Fibonacci series up to n."""
     a, b = 0, 1
     while a < n:
         print(a, end=' ')
         a, b = b, a+b
     print()
fib(100)
#我们之前写的都是直接print的,现在,我想获得运行的结果,而不是打印
def fib2(n):  # write Fibonacci series up to n
    """Print a Fibonacci series up to n."""
    a, b = 0, 1
    result = []
    while a < n:
        result.append(a)
        a, b = b, a + b
    return result
fibresult = fib2(20)
print(fibresult)

#Default Argument Values  默认参数值
#四个参数,一个没有默认值,另外两个有
def ask_ok(prompt, retries=4, reminder='Please try again!'):
    while True:
        ok = input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise ValueError('invalid user response')
        print(reminder)
#w我们函数调用之传入了一个值
print(ask_ok('Do you really want to quit?'))
print(ask_ok('Do you really want to quit?',retries=1))
#ask_ok() missing 1 required positional argument: 'prompt'
print(ask_ok())
#没有默认值的一定要传参数,否则会报错,有默认值的可以不传参数,因为有默认值
#后面我们进行机器学习算法调优的时候会用到,因为,默认的算法都带有默认的参数,
#但是这个参数不是最优,要根据我们的实际情况来选择参数
#!/usr/bin/pyhon3
#这是我的第一个python
# this is the first comment
spam = 1  # and this is the second comment
          # ... and now a third!
text = "# This is not a comment because it's inside quotes."
print(spam)
print(text)
#python中,将所有除返回的类型都是float(带小数点的)
print(type((50 - 5*6) / 4))
#如果我们就想要返回一个整数
print(((50 - 5*6) // 4))
#取余
print(17 % 3)
print(5 * 3 + 2)
#python做幂的运算
print(5**2)
print(2**7)
print(pow(5,2))
print(pow(2,7))
#进行简单的赋值操作
w = 20
h = 50
print(w*h)
#第一个报错,未定义的错
# NameError: name 'n' is not defined
#print(n)
# int a;默认是0

#float类型和int类型混合运算,会转化为float
print(4 * 3.75 - 1)
#和java不同,这里能编译过,表示3个‘aaaa’
print(3*"aaaa")
#Str类型
print("ruozei")
#转义符号
print('ruo\'zei')
print("\"Yes,\" they said.")
#这里需要注意一下,python中,\u 表示后面的都是unicode编码
#加一个字母r 来让我们的转义无效
print(r"C:\Users\11725\PycharmProjects\pythonLearning\ruozei-python\__init__.py")
print(r"first line \n second line")
#多行字符串的问题
#加\ 表示这一行还没有结束,后面还有内容
print("""\
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to
""")
#字符串拼接
print(3 * 'un' + 'ium')
print('py'  'thon')
#变量和字符串直接拼接是不行的,要加上+好
prefix = 'Py'
#invalid syntax
#print(prefix  'thon')
print(prefix+'thon')
#python数组的一些内容
word = 'Python'
print(word[0])
print(word[5])
#如果我填写了超过字符串长度的索引
#IndexError: string index out of range
#print(word[6])
#从后往前的索引
print(word[-1])
#区别,正索引是0到5   负索引是-1 到-6

#python还支持切片的操作
#我们想取 0和1  但是,我们要写到2
print(word[0:2])
#在索引中加入':',':'之前的,默认从0开始
#':'后面的,默认是到最后字符
print(word[:2])
print(word[2:])
print(word[:])
#
#  +---+---+---+---+---+---+
#  | P | y | t | h | o | n |
#  +---+---+---+---+---+---+
#  0   1   2   3   4   5   6
# -6  -5  -4  -3  -2  -1
print(word[4:42])
print(word[42:])
#我们不能把字符串的内容取出来重新复制
#TypeError: 'str' object does not support item assignment
#报的错要注释,否则,编译会卡在这里,进行不到下面
#word[0] = 'j'
#但是支持取出里面的内容,重新组成字符串
print('J' + word[1:])
print(len(word))
#python列表
squares = [1, 4, 9, 16, 25]
print(squares)
print(squares[0])
print(squares[-1])
#列表可以和其他列表相加
print(squares + [36, 49, 64, 81, 100])
#列表是支持重新赋值
squares[0] = 121
print(squares)
#列表添加元素 列表不需要类型一致
squares.append('aaa')
print(squares)
#其他操作
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
letters[2:5] = []
print(letters)
letters[:] = []
print(letters)
#两个列表结合
a = ['a', 'b', 'c']
n = [1, 2, 3]
x = [a, n]
print(x[0][1])

##First Steps Towards Programming
#换行的话,加':',下一行前面是tab空格符
a,b = 0,1
while b<100:
    print(b)
    a, b = b, a + b
i = 100
print('The value of i is',i)

 

你可能感兴趣的:(Python)