• Welcome to ForumKorner!
    Join today and become a part of the community.

Python tutorial - Strings & outputs

Glubz

User is banned.
Reputation
0
[font=Tahoma, Verdana, Arial, sans-serif]Hello and welcome to another Python tutorial. In this tutorial I'll be teaching you strings and outputs. [/font]

[size=small]Strings[/size]
A string is usually a piece of text you want to display to someone, or "export" out of the program you are writing. Python knows you want something to be a string when you put either (double-brackets) or ' (single-quotes) around the text (IN VERSION 3+. A string is always defined using '= '.

Output
[font=Tahoma, Verdana, Arial, sans-serif]It's in the name really. You can use outputs to display the person's input, an output is always defined by using 'print'. You can use outputs for various attributes; in this tutorial I'll be using them for strings.[/font]

[font=Tahoma, Verdana, Arial, sans-serif]NOTE: I'm using Python 2.7.10, it's by far the easiest and most efficient version of Python[/font]

Code (the hashes explain what the individual commands do): 

Code:
kudos = raw_input("How many kudos do I deserve?: ") #In this case, the 'kudos' will be what the user has made an input on
kudos_you = raw_input("How many do you deserve?: ") #raw_input allows the user to type whatever they feel free to
username = raw_input("What is your dream username (lol sad): ") #The question is always opened by (" and then a closing ")



print "So, you think I deserve exactly %s" % (kudos) #The 'print' command is simple, it prints (kudos) which is what the user has typed
print "kudos, you think you deserve %s" % (kudos_you) #A printed string is always defined by opening and closing brackets beginning with a %
print "kudos and your dream username is %s" % (username) #Always end your output with %s then a ", the %s is initially from the language C
print "Thanks for entering my interesting quiz." #Just a random end quote
I hope this tutorial was simple and I hope to do many more in the future.
 
Top