0

Something python did not tell me i assumed it was like this for all codes to start.

In the beginning of python codes you put these >>> what are they for because i tried entering it like this. >>> print ( 1 + 2 ) And it gave me a syntax error What are these >>> used for Is it used for non numerical?

20th Nov 2018, 6:04 PM
Morne Slabbert
Morne Slabbert - avatar
11 odpowiedzi
+ 3
>>> is just the interpreter prompt for Python. We don't need it if we run a code in the Code Playground.
20th Nov 2018, 6:08 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Yep! And even when using an interpreter, you wouldn't need to manually type the >>>. It'd be displayed there automatically.
20th Nov 2018, 6:10 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Haha! You're welcome! :)
20th Nov 2018, 6:13 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Those are two different things. "2" and "3" are strings. "2" + "3" concatenates (puts them side-by-side) those two strings to get the new string "23". But if we just did 2 + 3, that would be adding the numbers 2 and 3. The result is 5. Does that make sense? You'll soon learn more about them in the tutorial.
20th Nov 2018, 6:17 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Yes, doing 2 + 3 would be much better than int("2") + int("3") in that case. But as you'll soon see, sometimes we don't have a choice. It was just an illustration.
20th Nov 2018, 6:23 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
print ( 1 + 2 ) Is this the way i code it then?
20th Nov 2018, 6:09 PM
Morne Slabbert
Morne Slabbert - avatar
0
You are a king! Thanks!
20th Nov 2018, 6:11 PM
Morne Slabbert
Morne Slabbert - avatar
0
Last question i promise lol print "2" + "3" 23 Why would i want to use the double quotation Wouldn't print (2 + 3) Be easier?
20th Nov 2018, 6:14 PM
Morne Slabbert
Morne Slabbert - avatar
0
Yes the tutorial said if i want the concatenates to add "2" + "3" to get 5 i need to... int("2") + int("3") To get 5 or something like that Why not just take it to the original math instead of going around it like that?
20th Nov 2018, 6:21 PM
Morne Slabbert
Morne Slabbert - avatar
0
Or is it to convert strings into intergers sorry if it is converting lol
20th Nov 2018, 6:22 PM
Morne Slabbert
Morne Slabbert - avatar
0
I just got confused but i do see now that it is to convert strings to intergers... I feel stupid now
20th Nov 2018, 6:24 PM
Morne Slabbert
Morne Slabbert - avatar