python String Study log

1. "" , ‘‘, """   """

2. Strings are stored as sequences of characters indexed by integers, starting at zero.

3. To extract a substring, use the slicing operator s[i:j].

4. Strings are concatenated with the plus (+) operator:

g = a + " This is a test"

5. To perform mathematical calculations, strings first have to be converted into a numeric

value using a function such as int() or float(). For example:

z = int(x) + int(y) # z = 79 (Integer +)

6. Non-string values can be converted into a string representation by using the str(),

repr(), or format() function.

时间: 2024-08-02 04:00:53

python String Study log的相关文章

Python string objects implementation

http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects implementation June 19, 2011 This article describes how string objects are managed by Python internally and how string search is done. PyStringObject structu

The internals of Python string interning

JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A few days ago, I had to explain to a colleague what the built-in function intern does. I gave him the following example: >>> s1 = 'foo!' >>>

Python string interning原理

原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何工作的,代码基于CPython2.7.7这个版本. 前一段时间,我向同事解释了python的buil-in函数 intern背后到底做了什么.我给他看了下面这个例子: >>> s1 = 'foo!' >>> s2 = 'foo!' >>> s1 is s2

python string

string比较连接 >>> s1="python string" >>> len(s) 13 >>> s2=" python string2 " >>> s=s1+s2 >>> s 'python string python string2 ' >>> >>> cmp(s1,s2) 1 string 截取 >>> s1[0

Python的DEBUG LOG

一直在嵌入式行业,熟悉嵌入式的朋友都很了解嵌入式设备上DEBUG的麻烦,特别是一些缺乏断电工具和没有UI界面的设备.久而久之,开发一个新东西,首先就是要先搞定DEBUG手段.最近写了几个测试的python脚本用于跑些压力测试.找了些Python的DEBUG方法并加以处理,形成了方便使用的DEBUG手段. 其实Python的DEBUG LOG很简单很方便,相当于整辆车都做好了,就等你怎么开车了.而我们在C的嵌入式设备上,DEBUG都几乎需要自己造轮子,造车身.然而在Python中我们只需要impo

python 实现 math.log(x,base)

python 用闭包实现math.log(x,base) #!/usr/bin/python3 # -*- coding: utf-8 -*- import sys,math import random import pprint def log(n,d): i = 0 status = 0 while True: if d**i==n: status=1 break elif d**i<n<d**(i+1): break i+=1 def test(level=100): if status

python string操作

#!/bin/python #-*- coding=utf-8 -*- import string print("hello,world") str1 = "       python是动态语言       " #打印str1原型 print(str1) #打印去掉两边空格 print(str1.strip()) #字符串大小写转换 str2="abcd EFG,this is a TEST" print(str2.lower()) #小写 pr

python string与list互转

因为python的read和write方法的操作对象都是string.而操作二进制的时候会把string转换成list进行解析,解析后重新写入文件的时候,还得转换成string. import string str = 'abcde' list = list(str) list ['a', 'b', 'c', 'd', 'e'] str 'abcde' str_convert = ''.join(list) str_convert 'abcde'

Python String的一些方法

0x01 count str.count(sub[, start[, end]]) 用来统计字符串中某个字符的个数 1 text = "abcabcabc" 2 text.count("a") 3 #output: 3 4 text.count("a", 0) 5 #output: 3 6 text.count("a", 2, 4) 7 #output: 1 0x02 find 1 str.find(sub[, start[,