str()
Python Built in functions in Python
Convetring object to string.
str(object,encode='utf-8',errors='strict')
object : ( Required ) The object which is to be coverted to string
encode : ( Optional ) default is 'utf-8'
errors : ( Optional ) what to do if error occurs.
print(str(3.4)) # 3.4
Using type
print(type(str(3.4))) # <class 'str'>
Using bytes
my_str = "plus2net.com"
# encoding 'utf-8'
my_bytes = bytes(my_str, 'utf-8')
print(my_bytes) # b'plus2net.com'
print(type(my_bytes)) # <class 'bytes'>
print(str(my_bytes, encoding='ascii', errors='ignore'))# plus2net.com
Data type of string object
We used type() to get data type of any string object.
my_str='plus2net'
print(type(my_str)) # <class 'str'>
« All Built in Functions in Python repr()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com