返回顶部
首页 > 资讯 > 后端开发 > Python >python note #1
  • 674
分享到

python note #1

pythonnote 2023-01-30 23:01:04 674人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

To record my process of studying python and to practice my English meanwhile, I'd like to start write my blog about Pyt

To record my process of studying python and to practice my English meanwhile, I'd like to start write my blog about Python with English. = ^ =

 

Part 1_Hello World!

 1 print (' Hello World! ') 

 

This code can show the best reason why I'd like to study python. Because it's so simple, clean and elegant. With python, setting language environment is not needed anymore. Just use 'print', everything is done!

 

Part 2_History & Development of Character Encoding

  • ASCII: best for English, which only takes up 1 bytes of your storage. 

 

  • Chinese: take up 3 bytes

  • Unicode: ISO released unicode to unite diffrent standards of character encoding between countries. But it took up 2 bytes to store English. To improve it, utf-8 was released. With utf-8, only 1 bytes was needed while storing English.

 

Part 3_Variety

Rules

  •   Combination of character, number and underscores.
  •   Don't use key Words as the name of the variety.
  •   Name the variety with its meaning.
  •   With CapiTAL LETTERS naming a variety, it means that the variety is constant.

How to use?

1 name = 'It's a Good day!'
2 # name a variety
3 name2 = name
4 # give a value to a new variety
5 print (' What' the weather like today?', name, name2)
6 # use varieties
variety
 1 '''
 2 function1:多行注释
 3 function2:多行打印
 4 '''
 5 message='''
 6 Do you like this blog?
 7 If yes, that's great!
 8 If no, leave you suggestions, and I'll improve it ASAP!
 9 '''
10 print(message)
usage of '''

 

 Part 4_Interaction

'Input' is used to get infORMation from users. And 'print' is used to output the information.

 1 name = input (' Please input your name:')
 2 age = input("Please input your age:") 
 3 #加入int,代表integer,整型,字符串的格式化
 4 job = input("Please input your job:")
 5 salary = input("Please input your salary:")
 6 
 7 info = '''
 8 -------------------info of {NAME} --------------------------
 9 NAME: {NAME}
10 AGE: {AGE}
11 JOB: {JOB}
12 SALARY: {SALARY}
13 ----------------------------------------------------------------
14 ''' .format(NAME=name, AGE=age, JOB=job, SALARY=salary)
15 
16 print (info)
interaction

 

Part 5_Loop ( if, elif, for, while )

Combination of If, While and Elif

Qiao is one of my roomates. To show my respect for her, I took advantage of her birth year information to write a code for you to guess. Ofcourse, please do not read the code directly. Cuz in this way, you'll get the answer directly...

 1 birthyear_of_qiao = 1997
 2 count = 0
 3 while count<3:
 4     guess = int(input("猜猜乔的出生年份:"))
 5     if guess == birthyear_of_qiao:
 6         print("干的漂亮,你猜对了!")
 7         break
 8     elif guess > birthyear_of_qiao:
 9         print("她哪有那么年轻?!!!")
10     else:
11         print("她还没那么老,好嘛。。。")
12     count +=1
13     if count == 3:
14         if_continue = input('是否要继续呢?继续的话请输入Y,退出的话请输入N:')
15         if if_continue == 'Y':
16             count = 0
17         else:
18             print ('猜不中还早早退出,太塑料兄弟情了!')
19             break
20 else:
21     print('游戏失败。。。')
loop_if_while_elif

For

 1 # continue是跳出本次循环,进入到下一次循环
 2 # break是结束全部循环
 3 for i in range(0,10,2):
 4     if i <5:
 5         print("loop",i)
 6     else:
 7         continue
 8     print('嘻嘻')
 9 
10 # 循环套循环,执行一次大循环,下面执行六次小循环
11 for i in range(10):
12     print ('-------------------',i)
13     for j in range(10):
14         print(j)
15         if j>5:
16             break

 

--结束END--

本文标题: python note #1

本文链接: https://lsjlt.com/news/181361.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • python note #1
    To record my process of studying python and to practice my English meanwhile, I'd like to start write my blog about pyt...
    99+
    2023-01-30
    python note
  • python note
    1.新建一个项目django-admin.py startproject project_name2.新建一个APPpython manage.py startapp app_name 3.DB操作Django 1.7.1及以上 用以下命令...
    99+
    2023-01-31
    python note
  • aaron note python
    开源工程shedskin,可以将Python代码翻译、编译成C++代码。使用起来极为方便,因为它自带了开源的C++编译器mingw32SPE: a very good python editorDreamPie: a very good p...
    99+
    2023-01-31
    aaron note python
  • Note of Python Turtl
    Note of Python Turtle         Turtle 库函数是 Python语言中一个流行的绘图函数库。Turtle 意思是海龟,在Python中显示为一个小箭头,通过它的移动而留下美妙的曲线~~~ 1.调用库函数 (...
    99+
    2023-01-30
    Note Python Turtl
  • python 1
    用正则给ip对应的mac分割[root@room1pc01 桌面]# cat  ipmac.txt   192.168.4.5   121212452242   192.168.4.2   242426231251   192.168.4....
    99+
    2023-01-31
    python
  • python (1)
         1.解释型的,面向对象的,带有动态语义的高级程序设计语言。      2.使用Python    3.Python和c脚本的区别Python脚本  ** #coding:utf-8      设置编码格式c脚本    运行    ...
    99+
    2023-01-31
    python
  • Python(1)
    一、简介:1、Python语法简洁清晰,强制使用空格符作为语句缩进,来分割代码块。      Python在设计上坚持了清晰划一的风格,这使得Python成为一门易读、易维护,并且被大量用户所欢迎的、用途广泛的语言。      Python...
    99+
    2023-01-31
    Python
  • Python------1
    封装:把同一功能的放一块。 继承:追根溯源。 类是对象的蓝图和模板,而对象是类的实例。 实例: claddname = Classesname 函数的写法: 如下图所示: 类: 如图所示: 在...
    99+
    2023-01-31
    Python
  • python[::-1][::-1,::-1]的具体使用
    目录一、 [::-1]二、 [::-1,::-1]一、 [::-1] import numpy as np import numpy as np x = np.arange(1, ...
    99+
    2024-04-02
  • 详解python中[-1]、[:-1]、[::-1]、[n::-1]使用方法
    [m : ] 代表列表中的第m+1项到最后一项 [ : n] 代表列表中的第一项到第n项 [-1] 代表去到最后一项 [:-1]代表除了最后一个都获取到 [::-...
    99+
    2024-04-02
  • Note of Jieba ( 词云图实
    Note of Jieba jieba库是python 一个重要的第三方中文分词函数库,但需要用户自行安装。 一、jieba 库简介   (1) jieba 库的分词原理是利用一个中文词库,将待分词的内容与分词词库进行比对,通过图结构和动...
    99+
    2023-01-31
    云图 Note Jieba
  • SAP Important note on transporting tax codes
    SAP Important note on transporting tax codes This the SAP procedure: Important note on transporting tax codes ...
    99+
    2023-06-05
  • Python Road 1
    利用博客来捋一遍Python的基础知识,看一看有没有遗漏的有趣的语法和知识,当然此博客也适用于入门小白,或许从某些方面来说比Python教程更能帮助到你。 一、Python环境: 二、列表和元组 列表和元组的主要区别在于,列表可以修改,...
    99+
    2023-01-30
    Python Road
  • zero python.1
    1.变量  2.流程控制  3.序列、字典、集合  4.文件  1.变量 程序中用来保存数据。定义时,不用指定变量类型,输出时使用print直接输出:>>> say = 'hello Python' >>>...
    99+
    2023-01-31
    python
  • opencv——python(1)
    导入opencv模块 import cv2 2.导入numpy模块 import numpy as np 3.读取当前目录图片 img = cv2.imread("1.jpg") 4.创建图像 emptyImage = ...
    99+
    2023-01-31
    opencv python
  • SAP QM怎么维护Internal Note
    这篇文章主要介绍“SAP QM怎么维护Internal Note”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“SAP QM怎么维护Internal Note”文章能帮助大家解决问题。QM02在如下的...
    99+
    2023-06-05
  • SAPCAR该如何解压SAP NOTE
    SAPCAR该如何解压SAP NOTE,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。SAPCAR 下载并安装。SAPCAR在Windows版的软件名就是sapcar.exe...
    99+
    2023-06-05
  • python中的[1:]、[::-1]、X[:,m:n]和X[1,:]的使用
    目录Python中的[1:]Python中的[::-1]Python中的X[:,m:n]和X[1,:]Python中的[1:] 意思是去掉列表中第一个元素(下标为0),去后面的元素进...
    99+
    2024-04-02
  • python练习(1)
    文章目录 一、if语句—未满十八岁禁止入内二、判断一个数是否能同时被3和7整除三、判断你一个数能同时被3或者7整除 但不能同时被3和7整除四、输入年份 判断是否为闰年五、定义两个变量 保存一个...
    99+
    2023-09-01
    python
  • Python学习 (1)
    一、基本语法: import 与 from...import 在 python中 用import 或者from...import 来导入相应的模块。 将整个模块(somemodule)导入,格式为:import somemodule 从...
    99+
    2023-01-30
    Python
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作