#!/usr/bin/env python # coding: utf-8 # **Hello,World** # In[2]: print ("Hello, World!") # ### 数字和表达式 # #### 加法 # In[3]: 2+2 # In[4]: 53672+235253 # In[5]: 1/2 # In[6]: 1.0/2.0 # In[7]: 1/2.0 # In[8]: 1/2. # In[11]: from __future__ import division 1/2 # In[12]: 1//2 # In[13]: 1.0//2.0 # In[16]: 1%2 # #### 普通除法 # In[17]: 10/3 # #### 整除 # In[20]: 10//3 # #### 取余(模除) # In[22]: 10%3 # ** 乘法 ** # In[25]: 2 * 3 # #### 乘方 # In[29]: 2 ** 3 # #### 十六进制 # In[50]: 0xAF # #### 八进制 # In[54]: 0o10 # #### 二进制 # In[57]: 0b11 # ### 变量 # In[60]: x = 2 # In[62]: x * 2 # In[71]: y = x # In[73]: x = 1 # In[75]: y # ### 语句 # In[64]: 2 * 2 # In[68]: print (2*2) # In[76]: input("The meaning of life:") # ### 获取用户输入 # In[77]: x = input("x:") # In[81]: y = input("y:") # In[85]: x= int(x) # In[86]: y = int(y) # In[88]: print (x*y) # In[89]: if 1==2: print('One equals Two') if 1 ==1: print('One equals One') # ### 函数 # # In[90]: 2 ** 3 # In[91]: pow(2,3) # In[92]: abs(-10) # In[94]: round(1.0/2.0) # ### 模块 # In[97]: import math math.floor(32.9) # In[101]: float(math.floor(32.9)) # In[99]: from math import sqrt sqrt(9) # In[100]: int(sqrt(9)) # In[106]: import cmath cmath.sqrt(-1) # In[107]: (1+3j)*(9+4j) # ### 字符串 # In[108]: "Hello,Python" # In[109]: 'Hello,Python' # In[119]: "let\'s go!" # In[111]: "\"Hello,Pyrhon\"" # In[120]: x= 'Hello,Python,' # In[113]: y= "let\'s go!" # In[117]: print(x+y) # In[123]: repr("Hello,World!") # In[124]: str("hello,World!") # ### 新函数 # In[125]: abs(-10) # In[126]: cmath.sqrt(-9) # In[127]: float(3) # In[128]: help() # In[130]: input(x) # In[131]: int(3.0) # In[137]: math.ceil(2.5) # In[138]: math.floor(2.5) # In[139]: math.sqrt(9) # In[140]: pow(2,3) # In[145]: repr("Hello,World!") # In[146]: round(2.21323531453465) # In[147]: str("Hello,World~")