python学习day1

这篇博客介绍了Python中的字符串操作,包括赋值、字符串拼接、转义字符、字符串乘法以及多行字符串的使用。同时,展示了两个简单的猜数字游戏的设计,涉及条件判断和循环结构。通过这些例子,读者可以更好地理解Python的基础语法和控制流程。
摘要由CSDN通过智能技术生成

 

 

 

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

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


print("I love pytnon.\nI love me.")
I love pytnon.
I love me.

print('I love pytnon.\nLet\'s love me.')
I love pytnon.
Let's love me.


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

原始字符
print(r"D:\three\two\one\now")
D:\three\two\one\now         

一句话的末尾加\表示没完
print("D:thre\n\ yy")
D:thre
\ yy

长字符串
print("""1
2
3""")    
1
2
3

字符串乘法
print("我每天爱自己三遍!"*3)
我每天爱自己三遍!我每天爱自己三遍!我每天爱自己三遍!

print('\\')     
\

print("D:\three\two\one\now")
D:	hree	wo\one
ow

字符串加法=拼接
'520'+'1314'    
'5201314'



"""用python设计第一个游戏"""

temp=input("不妨猜一下现在咩咩心里想的数字:")
guess=int(temp)

if guess==8:
    print("你是咩咩心理的蛔虫么")
    print("哼,猜中了也没奖励")
else:
    print("猜错啦")

print("游戏结束")




"""用python设计第一个游戏"""

counts=3
while counts>0:
    temp=input("不妨猜一下现在咩咩心里想的数字:")
    guess=int(temp)

    if guess==8:
      print("你是咩咩心理的蛔虫么")
      print("哼,猜中了也没奖励")
      break
    else:
      if guess<8:
        print("小啦~")
      else:
        print("大啦~")
    counts=counts-1


print("游戏结束")


print('I love pytnon.\nLet\'s love me.')
      
I love pytnon.
Let's love me.
print('\\')
      
\
print("D:\three\two\one\now")
      
D:    hree    wo\one
ow
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值