zoukankan      html  css  js  c++  java
  • 【Python基础编程012 ● Python入门 ● 字符串与整数的运算 】


     ---------Python基础编程---------

    Author : AI菌


    【内容讲解】

    # 字符串与整数不能相加
    # "hello" + 10  # TypeError: must be str, not int
    
    # 把字符串复制n次,就是连续拼接n次
    print("hello" * 3)  # hellohellohello
    
    # 两个字符串可以相加 , 这里的 + 是字符串连接符的意思,用来连接两个字符串的
    print("hello" + "python")  # hellopython
    print("hello" + "python" + "ai")  # hellopythonai
    
    # 布尔类型的值可以与数字直接运算, True作为1,False作为0
    print(True + 1)  # 2
    print(False + 1)  # 1

    【代码演示】

    # 字符串与整数不能相加
    # "hello" + 10  # TypeError: must be str, not int
    
    # 把字符串复制n次,就是连续拼接n次
    print("hello" * 3)  # hellohellohello
    
    # 两个字符串可以相加 , 这里的 + 是字符串连接符的意思,用来连接两个字符串的
    print("hello" + "python")  # hellopython
    print("hello" + "python" + "ai")  # hellopythonai
    
    # 布尔类型的值可以与数字直接运算, True作为1,False作为0
    print(True + 1)  # 2
    print(False + 1)  # 1

    【往期精彩】

    ▷【Python基础编程196 ● 读取文件的4种方式】
    ▷【Python基础编程197 ● 读取文件的4种方式】
    ▷【Python基础编程198 ● 读取文件的4种方式】
    ▷【Python基础编程199 ● Python怎么读/写很大的文件】
    ▷【Python基础编程200 ● 读取文件的4种方式】
    ▷【Python基础编程201 ● 读取文件的4种方式】
    ▷【Python基础编程202 ● 读取文件的4种方式】
    ▷【Python基础编程203 ● 读取文件的4种方式】

    【加群交流】



  • 相关阅读:
    编程之美1的个数统计
    组合以及可以重复的排列
    Swing之图书管理系统
    经常熬夜的人一定要看
    利用SharePoint Designer开发可循环工作流
    SharePoint Software DownLoad Address 微软软件 下载地址
    日期验证 正则表达式
    时间验证 正则表达式
    Reporting Services SharePoint AddIn Setup Problems
    char、varchar、text和nchar、nvarchar、ntext的区别
  • 原文地址:https://www.cnblogs.com/hezhiyao/p/13518268.html
Copyright © 2011-2022 走看看