zoukankan      html  css  js  c++  java
  • python



    # -*- coding:utf-8 -*-

    '''
    @project: jiaxy
    @author: Jimmy
    @file: study_2_str.py
    @ide: PyCharm Community Edition
    @time: 2018-11-01 15:12
    @blog: https://www.cnblogs.com/gotesting/

    '''


    # 字符串
    s = '' #空字符串
    # 1:字符串拼接
    # 1.1:字符串与字符串的拼接用 + 连接

    s_1 = 'hello'
    s_2 = 'world'
    s_3 = 5201314

    new_s_1 = s_1 + s_2
    print('拼接后的字符串:',new_s_1)

    # 1.2:如果是字符串和数字拼接,可以将数字强制转换成字符串 str()

    new_s_2 = s_1 + s_2 + str(s_3)
    print('字符串与数字拼接:',new_s_2)


    # 2:字符串的格式化输出
    # % 占位符/占坑符 : %s 字符串; %d 整数 ;%f 浮点数
    name = 'Jimmy'
    course = 'Python'
    class_id = 12
    age = 18
    salary = 1000000


    print('''======== Jimmy's info =======
    姓名:%s
    课程:%s
    班级:%d
    年龄:%d
    薪酬:%d
    ========= Wishing ===========
    ''' %(name,course,class_id,age,salary)

    )

    # 格式化输出方式二 format {}

    # {}不指定数据 按顺序赋值
    print('''======== Jimmy's info =======
    姓名:{}
    课程:{}
    班级:{}
    年龄:{}
    薪酬:{}
    ========= Wishing ===========
    ''' .format(name,course,class_id,age,salary)

    )

    # {}里面指定数据,按照指定数据赋值
    print('''======== Jimmy's info =======
    姓名:{4}
    课程:{3}
    班级:{2}
    年龄:{1}
    薪酬:{0}
    ========= Wishing ===========
    ''' .format(name,course,class_id,age,salary)

    )

    print('我是{},我今年{}岁'.format('Jimmy',18))



    
    
  • 相关阅读:
    Keras入门(一)之基础篇
    Keras.layers各种层介绍
    python 深度学习
    git 与 tfs 源代码迁移工具
    使用RazorGenerator和预编译MVC引擎将Razor视图编译成DLL
    python资源
    .net Core 资源
    【ElasticSearch】win10 安装elasticSearch 6.6.1
    代码注释主要有哪几种
    html和css基础知识
  • 原文地址:https://www.cnblogs.com/gotesting/p/9889670.html
Copyright © 2011-2022 走看看