■ Program
Let's touch Python
Learn the basics of Python 2. String 3. Numerical value 4. Let's calculate
・ Let's output a character string (Example) print ('hello Python') (Point) Surround with single or double quotation marks ・ Numerical value (Example) print (3) (Point) Do not enclose numbers in quotation
Let's use variables 5. Variables 6. Let's use variables 7. Let's update the value of the variable 8. String concatenation 9. Data type
·variable (Example) name ='soarer' number = 48
・ How to name variables Good example (Example) date Use English words user_name Separate two or more words with an underscore
bad example (Example) 1name Start number namae use romaji Name Japanese
・ Concatenation of character strings (Example) print ('Hallo' +'Python')
-Update the value of the variable (Example) x = 48 print(x) x = 46 Overwrite variable value
・ Data type (Example)'Hello Python' string type 3 Numeric type
(Example) print (4 + 8) Numerical calculation result 12 print ('4' + '8') Character concatenation result 48
-Type conversion str (Example) price = 100 print ('The price of an apple is' + price +'Yen') print ('The price of an apple is' + str (price) +'Yen') ← Convert to string type with str
・ Type conversion int (Example) count = '48' price = 100 total_price = price * int (count) ← Convert to numeric type
Boolean value and conditional branching 10. if statement 11. Boolean value 12. else 13. elif 14. Let's combine conditional expressions
・ Conditional expression of if statement (Example) x == y Holds when the left and right values are equal x! = y holds when the left and right values are not equal
-Indent (indent) when writing the processing when the conditional expression of the if statement is satisfied.
・ Authenticity value
score = 100 if score == 100: ← colon
score = 100 print(score == 100)
True False
print(3 == 3) True print(3 == 5) False
score = 100 if score == 100: True holds
score = 50 if score == 100: True does not hold
・ Else (Example) score = 50 if score == 100: ← colon print ('well done') ← indent else: ← colon print ('Let's do our best')
・ Elif (Example) score = 70 if score == 100: ← colon print ('well done') ← indent elif score> = 60: ← colon print ('decent') ← indent else: ← colon print ('Let's do our best') You can enter as many elifs as you like The end ends with else
Let's calculate the shopping price 15. Let's calculate the price 16. Receive input 17. Let's do conditional branching
Python I is recommended because it is easy to understand even for beginners.
Recommended Posts