Python str 函数 - Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python str 函数 - Python零基础入门教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 一.Python str 函數介紹
- 二.Python str 函數使用
- 三.猜你喜歡
零基礎 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 str 函數
總結
以上是生活随笔為你收集整理的Python str 函数 - Python零基础入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过docker无法访问到tomcat报
- 下一篇: Python max 函数 - Pyth