str(object,encode='utf-8',errors='strict')
object : ( Required ) The object which is to be coverted to stringprint(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
my_str='plus2net'
print(type(my_str)) # <class 'str'>
pi = 3.14159
print(str(pi)) # Output: '3.14159'
my_list = [1, 2, 3]
print(str(my_list)) # Output: '[1, 2, 3]'
is_true = True
print(str(is_true)) # Output: 'True'
complex_num = 3 + 4j
print(str(complex_num)) # Output: '(3+4j)'
my_dict = {'name': 'Alice', 'age': 30}
print(str(my_dict)) # Output: "{'name': 'Alice', 'age': 30}"
my_tuple = (10, 20, 30)
print(str(my_tuple)) # Output: "(10, 20, 30)"
none_value = None
print(str(none_value)) # Output: 'None'
my_set = {1, 2, 3}
print(str(my_set)) # Output: '{1, 2, 3}'
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.