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

    【加群交流】



  • 相关阅读:
    移位运算符的限制
    数据类型
    正无穷和负无穷的问题
    dos下的cd指令
    c#线程的几种启动方法
    储过程实现简单的数据分页
    java 身份证15位转18位
    eclipse配置文件内存设置
    markdown语法学习
    js工具类
  • 原文地址:https://www.cnblogs.com/hezhiyao/p/13518268.html
Copyright © 2011-2022 走看看