1. 简单粗鲁的字符串拼接

1 name = "abc"
2 age = 25
3 info = "the name is "+name +"\nthe age is " + str(age)
4 print(info)

运行结果:

2.%

name = "abc"
age = 25
info = "the name is %s \nthe age is %s"%(name ,age)
print(info)

运行结果:

3.formate

name = "abc"
age = 25
info_1 = "the name is {name_} \nthe age is {age_}".format(name_=name ,age_= age)
print(info_1)
info_2 = "the name is {0} \nthe age is {1}".format(name ,age)
print(info_2)
info_3 = "the name is {} \nthe age is {}".format(name ,age)
print(info_3)

运行结果:

python 中字符串中含变量方法的更多相关文章

  1. python 统计字符串中指定字符出现次数的方法

    python 统计字符串中指定字符出现次数的方法: strs = "They look good and stick good!" count_set = ['look','goo ...

  2. c#中字符串截取使用的方法

    AndyZhang welcome to java world c#中字符串截取使用的方法 String substring(int beginIndex) String substring(int ...

  3. 【转】Java中字符串中子串的查找共有四种方法(indexof())

    原文网址:http://wfly2004.blog.163.com/blog/static/1176427201032692927349/ Java中字符串中子串的查找共有四种方法,如下:1.int ...

  4. Java中字符串中子串的查找共有四种方法(indexof())

    Java中字符串中子串的查找共有四种方法(indexof()) Java中字符串中子串的查找共有四种方法,如下:1.int indexOf(String str) :返回第一次出现的指定子字符串在此字 ...

  5. Java中字符串的一些常见方法

    1.Java中字符串的一些常见方法 /** * */ package com.you.model; /** * @author Administrator * @date 2014-02-24 */ ...

  6. Java中字符串indexof() 的使用方法

    Java中字符串中子串的查找共有四种方法(indexof())indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置.如果没有找到子字符串,则返回-1.如果 startind ...

  7. python之字符串中有关%d,%2d,%02d的问题

    python之字符串中有关%d,%2d,%02d的问题 在python中,通过使用%,实现格式化字符串的目的.(这与c语言一致) 其中,在格式化整数和浮点数时可以指定是否补0和整数与小数的位数. 首先 ...

  8. python 判断字符串中是否只有中文字符

    python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...

  9. python判断字符串中是否包含子字符串

    python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1:     print('存在') else:     print('不存在' ...

  10. Python 去除字符串中的空行

    Python 去除字符串中的空行 mystr = 'adfa\n\n\ndsfsf' print("".join([s for s in mystr.splitlines(True ...

随机推荐

  1. 【python实例】统计字符串里大写字母,小写字母的个数和非字母的个数

    """ 给定一个以下字符串:统计大写字母的个数,小写字母的个数,非字母的个数. str1 = "ajdkkKDKEK1343KFKiriromfkfKKRIOW ...

  2. day15 python lambda函数 递归函数 二分法

    day15 python   一.匿名函数 lambda     1.lambda函数 def func(n):                #普通函数, 功能比较简单, 当函数多的时候, 起名也不 ...

  3. oracle多表连接方式Hash Join Nested Loop Join Merge Join

    在查看sql执行计划时,我们会发现表的连接方式有多种,本文对表的连接方式进行介绍以便更好看懂执行计划和理解sql执行原理. 一.连接方式:        嵌套循环(Nested  Loops (NL) ...

  4. 人生苦短_我用Python_类与对象的概念_006

    Python类与对象的概念类和对象--->万事万物都对象物以类聚.人以群分 --->?划分标准性别分 男女 中性成绩分 优秀 良好 不及格 类->根据类的属性来划分类的实例-> ...

  5. centos 6.5 查看发行版本

    cat /etc/redhat-release 其他发行版 lsb_release -a

  6. favicon.ico设置

    <link rel="shortcut icon" href="media/image/favicon.ico" />

  7. boost timer

    Boost.Timer provides clocks to measure code performance. At first, it may seem like this library com ...

  8. webpack CSS处理loader

    loader概念: 首先来介绍一下loader,之前我们用webpack来处理我们写的js代码,并且webpack会自动处理js之间相关的依赖.但是,在开发中我们不仅仅有基本的js代码处理,我们也需要 ...

  9. spark streaming简单示例

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  10. Ext js-02 -官方API文档使用

    官方API文档地址: http://docs.sencha.com/extjs/6.5.3/classic/Ext.html 打开网页如下: 1.选择所使用的Ext js版本,后面offline do ...