I am a beginner and will challenge Python. Postscript: I made it into Python3 format.
I am running at Colaboratory.
~~ I will try to build the environment in Ubuntu. ~~ ~~http://qiita.com/pugiemonn/items/7257aa01897011469131~~
HelloWorld Print the string Hello World with print.
HelloWorld!
print("HelloWorld!")
Assign 10 to the variable.
Python
val_int = 10
val_float = 1.23
val_boolean = True
True and False have uppercase letters.
You can assign multiple variables by arranging ,
.
Assign multiple variables
a, b, c = 10, 30, 40
print(a)
print(b)
print(c)
#output
10
30
40
The list is an ordered list of values.
Python
number = [2, 40, 3]
string_text = ['a', 'b', '8']
#How to access the list
>>> number[1]
40
A hash of a pair of key and value. The dictionary does not keep the order.
Python
args = {80: 30, 2: 'piyo', 'hoge': 90}
#How to access the dictionary
>>> args[80]
30
>>> args["hoge"]
90
Use # for comments.
Python
#1 line comment
This is a multi-line comment.
Python
"""
It's a comment, oh oh oh oh
"""
I will calculate.
Python
hoge = 100 + 2200
hoge = hoge / 100
hoge = hoge * 2
print hoge # 46
Python
hoge = 10 ** 2
print hoge # 100
loop
i = 0
for _ in range(10):
i += 1
print i
#output
1
2
3
4
5
6
7
8
9
10
How to use the if statement.
vv = 50
if vv < 100:
vv = '00'
print(vv)
#output
00
If if is, or if, use ʻelsif`.
vv = 200
if vv < 100:
vv = '00'
elif vv < 1000:
vv = '0' + str(int(vv / 100))
print(vv)
#output
02
Python
h1 = input()
print(h1)
#input
10
#output
10
Python
h1 = input()
print(type(h1))
#input
10
#output
<class 'str'>
When entered, it will be of type str
.
It is managed by indentation.
Python
def spam():
hoge = 12
return hoge
print(spam()) # 12
I was able to combine strings with +
.
String concatenation
hoge = 'hoge'
print('piyo' + hoge)# piyohoge
Thank you for your hard work (☝՞ ਊ՞)
Recommended Posts