目錄
零基礎 Python 學習路線推薦 : Python 學習目錄 >> Python 基礎入門
一.Python str 函數介紹
在 Python 中 str 即可以表示 字符串 str 類型,也可以作為一個內置函數,可以直接將其他數據類型強制轉為字符串類型,語法如下:
'''
參數:
object — python數據類型對象;
返回值: 返回一個str類型的變量;
'''
str(object)
二.Python str 函數使用
# !usr/bin/env python
# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿說編程
@Blog(個人博客地址): www.codersrc.com
@File:Python str 函數.py
@Time:2021/04/20 07:37
@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!
"""
# 案例1: 將整形或者浮點數類型轉為str字符串類型
print(type(str(3.5)))
print(str(3.5))
print("***"*20)
# 案例2: 將字典轉為str字符串類型
dict1 = {'www': 'shuopython.com', 'google': 'google.com'}
print(type(str(dict1)))
print(str(dict1))
print("***"*20)
# 案例3: 將列表轉為str字符串類型
list1 = [1, 2, 3, 4]
print(type(str(list1)))
print(str(list1))
'''
輸出結果:
<class 'str'>
3.5
************************************************************
<class 'str'>
{'www': 'shuopython.com', 'google': 'google.com'}
************************************************************
<class 'str'>
[1, 2, 3, 4]
'''
三.猜你喜歡
- Python for 循環
- Python 字符串
- Python 列表 list
- Python 元組 tuple
- Python 字典 dict
- Python 條件推導式
- Python 列表推導式
- Python 字典推導式
- Python 函數聲明和調用
- Python 不定長參數 *argc/**kargcs
- Python 匿名函數 lambda
- Python return 邏輯判斷表達式
- Python 字符串/列表/元組/字典之間的相互轉換
- Python 局部變量和全局變量
- Python type 函數和 isinstance 函數區別
- Python is 和 == 區別
- Python 可變數據類型和不可變數據類型
- Python 淺拷貝和深拷貝
未經允許不得轉載:猿說編程 » Python str 函數
本文由博客 - 猿說編程 猿說編程 發布!