python学习日记1(安装+print功能)

第一篇博客...暑假都快过了才开始学python。坚持每天记录一下,没准以后写报告还能用上。

莫烦python学习   https://morvanzhou.github.io/tutorials/python-basic/basic/02-1-print/

 版本:python-3.7.0 windows

安装

官网下载

 https://www.python.org/getit/

downloads-->windows-->python-3.7.0

配置环境变量

安装的时候勾一下  Configuring environment variables (忘截图了,记不太清楚)

编译器IDLE  

按照这个教程找找就行  https://jingyan.baidu.com/article/148a1921ccc2f74d71c3b106.html

检验是否安装成功

打印数字1

>>> print 1
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(1)?

#python2.7及以下版本输出时不加(),我的是3.7需要加(),不加报错
>>> print(1)
1

#成功

print功能

输出字符串

>>> print('i have a pen')

      #单引号‘string字符串’
i have a pen
>>> print("i hava an apple")

      #双引号“string字符串”
i hava an apple
>>> print('apple'+'pen')

      #合体
applepen

转义字符

>>> print('you're a pig')

      # ’you‘ 你懂我的意思
      SyntaxError: invalid syntax
>>> print('you\'re a pig')
      you're a pig

类型转换

转成string有两种方法

>>> print(1+1)
      #自动计算
2
>>> print("1"+"1")
      #输出字符串
11

方法1:加引号

>>> print(4+'apple')
      #4是int型,编译错误
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    print(4+'apple')
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> print('4'+'apple')
      #4转成string型,正确编译
4apple

方法2:用str()

>>>  print(str(4)+'apple')
      #print前面多了个空格,报错
SyntaxError: unexpected indent
>>> print(str(4)+'apple')
      #用内置函数str()
4apple

 

输出2.33+2

>>> print(float(2.33)+2)
      #用内置函数float()
4.33

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值