Python基础教程第二版学习记录(一)

第一章 基础知识

  变量:(直接赋值) 

x = 4396

  输入:

input()

    或者

raw_input()  
#尽量使用raw_input(),它保留所有输入,记录成原始数据(raw data)放入字符串中

  模块:

# import 模块
# 例如:
import math 

    或者

# from 模块 import 函数
# 例如:
from math import sqrt

  转义:

\  #反斜线

  str()和repr():

    python中合法的字符串表达式是带有双引号''的,所以repr是将字符串转换为合法的表达式,而str则是将字符串转换为更容易让用户理解的形式,即str是表现给人看的,repr是表现给python看的

>>> print("hello world!")
hello world!

>>> print (str("hello world!"))
hello world!

>>> "hello world!"
'hello world!'

>>> print (repr("hello world!"))
'hello world!'

长字符串换行3种形式

#1
print '''Hello, 
world!'''
#2
print 'Hello, \
world!'
#3
print 'Hello, \n
world'
  


  

版权声明:本文为meeeec原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。