今日分享(三十六)python学习(3)
分享兴趣,传播快乐,增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。
今天小编为大家带来今日分享(三十六),欢迎您的访问!
Share interests, spread happiness, increase knowledge,
and leave a good legacy!
Dear you, this is The LearningYard Academy.
Today Xiaobian brings you today"s sharing (thirty six), welcome your visit!
实例分析——温度转换
(Case Study – Temperature Conversion)
目的为将随意给出的华氏度或摄氏度温度实现相互转换。
The purpose is to convert the temperature given arbitrarily to Fahrenheit or Celsius to each other.
#表示注释
TempStr、C、F为变量名,通常用"="进行赋值。图中,将随意输入的温度赋值给TempStr,C、F再由转换关系TempStr得到。
TempStr, C, F are variable names, usually assigned with "=". In the figure, the randomly entered temperature is assigned to TempStr, and C and F are obtained by the conversion relationship TempStr.
input表示输入信息
input represents the input information
索引:返回字符串中单个字符,如图中TempStr[-1],表示返回TempStr字符串中最后一个字符
Index: Returns a single character in a string, as shown in TempStr[-1] in the figure, indicating that the last character in the TempStr string is returned
切片:返回字符串中一段字符串。如图中TempStr[0:-1]表示返回TempStr字符串从第0个字符至倒数第二个字符。
Slice: Returns a piece of string in a string. As shown in the figure, TempStr[0:-1] indicates that the TempStr string is returned from the 0th character to the penultimate character.
分支语句:使用保留字if、elif、else构成条件判断的分支语句。
保留字所在行最后存在的一个冒号(:)
冒号及后续缩进用来表示后续语句与条件的所属关系。
in表示判断TempStr[-1]是否与in后面的一致。
Branch statement: Use the reserved words if, elif, and else to form a branch statement that constitutes conditional judgment.
A colon (:)) at the end of the line where the reserved word is located
Colons and subsequent indents are used to indicate the ownership of subsequent statements and conditions.
in indicates whether TempStr[-1] is consistent with the one following in.
eval函数:去掉参数最外侧引号并执行余下语句。如eval(TempStr[0:-1]),如果TempStr[0:-1]的值为"28.7",则输出的是28.7。
EVAL function: Remove the outermost quotation marks of the argument and execute the rest of the statement. For example, eval(TempStr[0:-1]), if the value of TempStr[0:-1] is "28.7", the output is 28.7.
今天的分享就到这里了。
如果您对今天的文章有什么独特的想法,
欢迎评论留言,让我们相约明天,
祝您今天过得开心快乐!
That"s it for today"s sharing.
If you have any unique ideas for today"s article, please leave a comment, let us meet tomorrow,
I wish you a happy day!
参考资料:《python程序设计》
翻译:谷歌翻译
本文由learningyard新学苑原创,部分文字图片来源于他处,如有侵权,请联系删除