python中的 upper() 、lower()、capitalize()、title()方法
upper()字符串中字母由小寫變為大寫
lower()字符串中字母由大寫變為小寫
capitalize()字符串中字母首字母大寫其余小寫
title()字符串中字母每個單詞的首字母大寫其余小寫
1 a = "hello"
2 b = "WORLD"
3 c = "hello"
4 d = "hello world"
5 a1 = a.upper()
6 b1 = b.lower()
7 c1 = c.capitalize()
8 d1 = d.title()
9 print(a1)
10 print(b1)
11 print(c1)
12 print(d1)
復制代碼
輸出結果:
HELLO
world
Hello
Hello World
python中的 upper() 、lower()、capitalize()、title()方法
相關推薦
Python中的元組,字典、計算器代碼實例及python2與python3的區別
所有 time tor result inpu __name__ 字符 img 歡迎來到 1.計算器實例#/usr/bin/env python # -*- coding:utf-8 -*- # @time :2018/1/22 21:09 # @Author :Fen
Python中的容器(container)、迭代器(iterator)和生成器(generator:yield)
1、容器迭代器iterator 以list容器(tuple,range,file類似)為例,list容器可以呼叫自己的__iter__()方法獲取用來迭代自己內部元素的迭代器。例如: # list容器 myList = [1, 2, 3] # 獲取list容器的迭代器 it
python中資料結構容器(list、dict、tuple、set)和C++、JAVA中的匯出資料型別, 陣列
list(列表):語法:列表形如 [1, 2, 3, 4] [‘小明’,‘小紅’,] ,用中括號括住,裡面是字串、布林,每一項逗號分開。 建立 宣告變數時 中括號、項,建立一個非空的列表。 num_list = [1,2,3,4] 建立一個空列表,之後再修改
python中字串拆分與合併——split()、join()、strip()和replace()
Python3 split()方法 描述 split()通過指定分隔符對字串進行切片,如果引數num 有指定值,則僅分隔 num 個子字串 語法 split()方法語法: str.split(str="", num=string
Python中的分組函式(groupby、itertools)
from operator import itemgetter #itemgetter用來去dict中的key,省去了使用lambda函式 from itertools import groupby #itertool還包含有其他很多函式,比如將多個list聯合起來。。 d1={'name':'zhangsa
Python中排序常用到的sort 、sorted和argsort函式
argsort函式返回的是陣列值從小到大的索引值 Examples -------- One dimensional array:一維陣列 >>> x = np.array([3, 1, 2]) >>> np.argsort(x) array([1, 2, 0]) T
python中7種實現單例模式的方法:staticmethod、classmethod、類屬性方法、__new__、裝飾器、元類、名字覆蓋
本文的以下實現方法為了簡單起見不考慮執行緒安全。 一:staticmethod 程式碼如下: class Singleton(object): instance = None def __init__(self): raise Syntax
python中的字元輸出(str()、repr()、print)
一、字元輸出的三種函式 str()、repr()、print 開發環境為python2.7 我們常常會遇到字元輸出和轉換問題,一個看似簡單的字元問題卻往往讓我們殫精竭慮。其實只要真的理解了,python的字元輸出轉換規則,這些問題再也不是問題了。 二、實
python中pickle使用,用於list、tuple、dict、set特殊的形式進行讀寫
自動 如果 python log char pycharm 二進制 pychar tom #特殊文件的讀寫,List tuple dict setimport pickle #數據持久性模塊myList=[1,2,3,4,5,"tom is a good boy"]path
python中的一維數組、行向量、與列向量
com 一維數組 ima .com info mage 技術分享 維數 bubuko 一維數組不是行向量也不是列向量, 一維數組: 行向量 加法 python中的一維數組、行向量、與列向量
orcl 中upper()和lower()和initcap()的用法
nbsp http 小寫 .com 大寫 per cap 方法 src upper(字符串 | 列):輸入的字符串變為大寫返回; 將 bqh4表裏的zym字段信息中含有字母的全部轉成大寫的方法: select * from bqh4 select upper(zym)
python中字符串(str)的常用處理方法
num replace 不同的 swa pos track con strong 位置 str=‘Python String function‘ 生成字符串變量str=‘python String function‘字符串長度獲取:len(str)例:print ‘%
Python中Gradient Boosting Machine(GBM)調參方法詳解
損失函數 二叉樹 lai 打印 探索 for tails 提示 原本 原文地址:Complete Guide to Parameter Tuning in Gradient Boosting (GBM) in Python by Aarshay Jain 原文翻譯與校對:@
python中常用的處理字符串的方法
sum cbac post OS 如果 ror 返回 cdb IT 1. find() 查看子序列的首個索引,沒有則返回-1 name = ‘aabcdbefg‘ c = name.find(‘b‘) print(c) 2 2.join()
Python中被雙下劃線包圍的魔法方法
按位異或 blog with pow ring 指定元素 運算 -c 描述 基本的魔法方法 __new__(cls[, ...]) 用來創建對象 1. __new__ 是在一個對象實例化的時候所調用的第一個方法 2. 它的第一個參數是這個類,其他的參數
Python中幾種數據的常用內置方法
改變 對象 count 似的 nds 字母 art number ali 1. int bit_lenth:二進制的長度 2.str capitalize():首字母大寫,其他小寫. upper():全部轉換為大寫,lower()相反;casefold()功能類
Python中常見字符串去除空格的方法總結
lac rip 生成 rst 字符串分割 進行 字符 分割 去除 Python中常見字符串去除空格的方法總結 1:strip()方法,去除字符串開頭或者結尾的空格>>> a = " a b c ">>> a.strip()‘a b c‘2
Python中遍歷pandas資料的幾種方法介紹和效率對比說明
前言 Pandas是python的一個數據分析包,提供了大量的快速便捷處理資料的函式和方法。其中Pandas定義了Series 和 DataFrame兩種資料型別,這使資料操作變得更簡單。Series 是一種一維的資料結構,類似於將列表資料值與索引值相結合。DataFrame 是一種二維
python中的排序函式sorted以及列表排序方法sort()
【時間】2018.10.30 【題目】python中的排序函式sorted以及列表排序方法sort() 概述 Python list內建sort()方法用來排序,也可以用python內建的全域性sorted()方法來對可迭代的序列排序生成新的序列。如果要讀取資料夾下面的
Python中os與sys模組區別及使用方法
1.定義 os 與 sys 模組的不同的官方解釋 os:提供一種方便的使用作業系統函式的方法 sys:提供訪問由直譯器使用或維護的變數和在與直譯器互動使用到的函式。 因此, sys 模組區別於 os 模組,sys 模組提供了一系列的函式和變數,用於操控 python 的執行時環境,