+ 2
What is the use of str in python?
???
15 Antworten
+ 2
The str() function of Python returns the string version of the object.
Syntax: str(object, encoding=’utf-8?, errors=’strict’) Parameters:
object: The object whose string representation is to be returned.
encoding: Encoding of the given object.
errors: Response when decoding fails.
Returns: String version of the given object
# Python program to demonstrate
# strings
# Empty string
s = str()
print(s)
# String with values
s = str("GFG")
print(s)
+ 6
Vishal Mourya
In python function str() is used to convert the specified value into a string.
+ 2
Thanks
+ 2
Vishal Mourya
str is a short name of string which is a function in python which takes 1 parameter.
number = 10
string = str(number)
Now number is converted into string, you can check using type function like this : print(type(string))
https://code.sololearn.com/cam8v49qqQ41/?ref=app
+ 2
Thanks
+ 2
Vishal Mourya check my shared code
+ 2
In python, str is an object (string), its a set of characters and it has a lot of functions. You can use it for eg.
str(20) -> "20"
str([20, 40]) -> "[20, 40]"
For more info you can try this:
help(str)
+ 2
str refers to string is a sequence of character enclosed in either single quotes double quotes or triple quotes
+ 2
In python str() is used to convert a particular value into string type.
+ 2
str() in pythn convert any value to string
Example
Num = 5
// now its an integer you can test it
print(type(Num))
Num2 = str(Num)
print(type(Num2))
// u see the dff
+ 1
Thanks
+ 1
Thank you
+ 1
It's give output in string format
+ 1
Thanks to all
0
In python how to use str,int in one program