How Can We Help?
Introduction:
In this tutorial, we are going to explain how to convert Python sequence to string function with basic syntax and many examples for better understanding.
Python sequence to string str(seq) function is used to convert a sequence into string.
Syntax:
str(sequence)
Input Parameters:
- sequence : Is a list /tuple/dictionary/float/integer etc, which needs to be converted into string.
Example
num1 = 0.12
print('Type of num before convert to str:',type(num1))
#convert variable value into string
num2=str(num1)
print('Type of num after convert to str:',type(num2))
print('Converted float value:',num2)
Example Output :
Type of num before convert to str: (class ‘float’)
Type of num after convert to str: (class ‘str’)
Converted float value: 0.12
In the above example, ‘num1’ is a float variable and ‘num2’ is a string variable. Here, ‘num2’ is created after converting ‘num1’ into string by using str(num1) so when we take the type of num1 and num2 variables, then result for num1 is float and num2 is string type.
In this tutorial, you have learned how to convert Python sequence to string by using str(seq) function.
If you have an inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback.But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Similar Python Functions to Convert Sequence to String:
- min(string) : It returns a minimum value of string.
- max(string) : It returns a minimum value of string.
- type(string) : It returns a maximum value of string.
- len(string) : It returns type of string, if passed variable is string.
- del(string) : It deletes whole string or individual string element or all element of string.
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list : access all python tutorials.