Python入门学习 1

>>> print("hello word")
hello word
>>> print("hello word")# this is mark    注 # 表示注释
hello word

>>> print(1+1) 
2       python 可用于数字运算,不限于数字的长度

>>> 986*969
955434

>>> print("this is python"+"i am yz") 两个语句可以叠加输出
this is pythoni am yz

>>> print("i am yz"* 3)
i am yzi am yzi am yz

>>> print("i am yz\n"* 3)   \n 表示特殊字符--换行
i am yz
i am yz
i am yz

以上的直接输出都是交互模式  点击File 选择  new File 可以进入编辑模式

我们·编辑一个 print("hello word") 点击 run module f5 输出 

就会得到

>>> 
========================== RESTART: D:/111/demo.py ==========================
hello word

我们还可以赋值 比如

>>> x = 3
>>> print("x")
x
>>> print(3)
3

>>> loveyou1314=1314
>>> print(loveyou1314)
1314

>>> 520love                                    注 变量名不能以数字开头 但可以中文开头
SyntaxError: invalid syntax 

 >>> 幸运数=588
>>> print(幸运数)
588

>>> x=3
>>> y=5
>>> x=y
>>> print(x)
5                       
赋值以最后一次为准

>>> x=y=3
>>> x
3
>>> y
3

>>> x=3
>>> y=5
>>> z=x
>>> x=y
>>> y=z
>>> print(x,y)
5 3   
   x y 互相交换数值 ,这样输出比较麻烦 python 里可用简单输出 如下

>>> x=3
>>> y=5
>>> x,y=y,x
>>> print(x,y)
5 3

单引号 双引号 可以用 \ 区分开  字符串末尾加上\表示还没有写完 这时换行不会输出

>>> print('\"life is short,let\'s learn python.\"')
      
"life is short,let's learn python."

>>> print("D:\\three\\two\\one\\")
      
D:\three\two\one\

>>> print(r"D:\three\two\one")  也可以给字符串前面加一个r
      

D:\three\two\one

>>> temp=input("你是谁")
      
你是谁
(输入)我是羊同学
>>> print(temp)
      
 我是羊同学

>>> temp=input("请输入一个数字")
      
请输入一个数字8
>>> guess=int(temp)
      
>>> print(guess)
      
8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值