Python打卡训练营学习记录Day2

day 2

字符串的操作

题目: 定义两个字符串变量,str1 赋值为 “Hello”,str2 赋值为 “Python”。将这两个字符串拼接起来(中间加一个空格),并将结果存储在变量 greeting 中;计算 greeting 字符串的长度,存储在变量 length 中;获取 greeting 字符串的第一个字符,存储在变量 first_char 中。然后,使用 f-string 分三行打印出类似以下格式的信息:

拼接结果: Hello Python

字符串长度: 12

第一个字符: H

第二个字符:e

最后一个字符是:n

str1 = "Hello"  
str2 = "Python"
greeting = str1 + " " + str2
length = len(greeting)
first_char = greeting[0]
second_char = greeting[1]
last_char = greeting[-1]
print(second_char)
print(last_char)
print(f"拼接结果:{greeting}\n字符串长度:{length}\n第一个字符:{first_char}")  

比较运算

题目: 定义两个整数变量,score_a 赋值为 75,score_b 赋值为 90。比较 score_a 是否大于 score_b,将比较结果(布尔值)存储在变量 is_a_higher 中;比较 score_a 是否小于等于 score_b,将结果存储在变量 is_a_lower_or_equal 中;比较 score_a 是否不等于 score_b,将结果存储在变量 is_different 中。然后,使用 f-string 分三行打印出类似以下格式的信息:

75 是否大于 90: False

75 是否小于等于 90: True

75 是否不等于 90: True

score_a = 75
score_b = 90
is_a_higher = score_a>score_b
is_a_lower_or_equal =score_a<=score_b
is_different =score_a!=score_b
print(f'75是否大于90:{is_a_higher}\n75是否小于等于90:{is_a_lower_or_equal}\n75是否不等于90:{is_different}')

@浙大疏锦行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值