1. Naming rules
1. The starting bit is the letter (case) or underline ('_')
2. Other parts are letter (case), underscore ('_') or number (0-9)
3. Case sensitive
2. Experience First :
#Ask the user their namename = input ("") # make the first letter ofTheir name upper case#an D The rest of the name lower case# and thenprint itprint (name[0].upper () + name[1:].lower ()) /c10>
Where # indicates a comment.
Note that when you enter a name, you need to use quotation marks to indicate that you are entering a string, otherwise idle will think you are typing an unnamed variable, error (name ' * * * ' is not defined)
3. Type conversion
Code similar to part 2nd:
num = input ("Enter A number:")answer = num*3print("" + answer)
When you enter 1, are you waiting for the program to output a 3 for you?
The result is an error (Cannot concatenate ' str ' and ' int ' objects) telling you that you cannot connect a string "Your ..." and an integer answer.
At this point we need the type conversion to tell idle that we need to print answer like a string.
1 num = input ("")2 answer = num*33print( "" + str (answer))
You might be wondering about line 2nd, why don't we tell Idle,num is a numeric variable, and it can handle num as a numeric variable? In this regard, poke the usual functions of the Python language, and follow the explanations of input (), Raw_input ().
Python language variables 2 (naming conventions, type conversions)