+ 3

What is the use of "str"

9th Jul 2017, 10:25 AM
GAURAV SHARMA
GAURAV SHARMA - avatar
2 Answers
+ 16
TheĀ strĀ coerces data into a string. Every datatype can be coerced into a string. For example : print(str(1.0/3.0)) # outputs 0.333333333333333 making it converted into a String. For more info : http://www.diveintopython.net/power_of_introspection/built_in_functions.html
9th Jul 2017, 10:33 AM
Dev
Dev - avatar
+ 3
In python "str" means "string" and if you are going to write a line of code texting (not about numbers) you really need to use it. When you run your code, you'll see its output and here strings are essentials. For example, if you want the output to be "Hello world!", you are going to do this: print ("Hello world!") This means that a string is created after using the double quotes. You can also use these ones: print ('Hello world!') In both cases, the output will be: Hello world! If your output has to show numbers you have to print them without strings: print (1, 2, 3, 4) or using lists: numbers = [1, 2, 3, 4] In both cases, the output will be: 1,2,3,4 but using lists you can do more stuff, as you'll see later. If you have any other doubt, check my posts. I hope I helped you!
9th Jul 2017, 10:43 AM
Zenkli
Zenkli - avatar