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种方式】

    【加群交流】



  • 相关阅读:
    SQL第一讲
    CSS3补充内容
    EXCEL数据导入SQL表的方法
    jq第四讲+实例
    jq第三讲
    jq第二讲
    安卓、苹果日历同步
    安卓、苹果手机备忘录同步
    服务器、客户端双认证
    今天我的博客正式开张了!
  • 原文地址:https://www.cnblogs.com/hezhiyao/p/13518268.html
Copyright © 2011-2022 走看看