专栏首页python3python note #1

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 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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • python的while循环

    while循环 #!/usr/bin/python #coding:utf-8 i=0 sum=0 while i<=99: i+=1 sum+=i print...

    py3study
  • 【Python3】Python函数

    作用域即范围(作用域关系是在函数定义阶段就已经固定的,与函数的调用位置无关) 查看作用域:globals(),locals()

    py3study
  • python 递归和二分法

      4. type() 返回类型    ord()  输入字符找字符编码的位置     chr()  输入位置找出对应的字符    ascii()判断给出的信息...

    py3study
  • 灾难性遗忘问题新视角:迁移-干扰平衡

    1. Catastrophic Forgetting and the Stability-Plasticity Dilemma

    用户1908973
  • 【论文推荐】最新七篇知识图谱相关论文—嵌入式知识、Zero-shot识别、知识图谱嵌入、网络库、变分推理、解释、弱监督

    【导读】专知内容组整理了最近七篇知识图谱(Knowledge graphs)相关文章,为大家进行介绍,欢迎查看! 1.Learning over Knowled...

    WZEARW
  • 自动驾驶共享多模态轨迹预测(CS AI)

    本文提出了一种用于预测在高度交互环境中交通未来轨迹的预测框架。基于自动驾驶车辆均配备有各类传感器(例如:LiDAR扫描器,RGB摄像扥)的现实条件下,本研究旨在...

    用户6868260
  • AlexNet论文总结

    Introduction Preconditions ImageNet Objects in realistic settings exhibit cons...

    Tyan
  • 【论文推荐】最新6篇行人重识别相关论文—深度空间特征重构、生成对抗网络、图像生成、系列实战、图像-图像域自适应方法、行人检索

    【导读】专知内容组整理了最近六篇行人重识别(Person Re-identification)相关文章,为大家进行介绍,欢迎查看! 1. Deep Spatia...

    WZEARW
  • 【论文推荐】最新七篇推荐系统相关论文—正则化奇异值、用户视角、CTR预测、Top-k、人机交互、隐反馈

    WZEARW
  • vae 相关论文 表示学习 1

    05 Nov 2016 (modified: 18 Apr 2017)ICLR 2017 conference submissionReaders: Ever...

    用户1908973

扫码关注云+社区

领取腾讯云代金券