Beginners practice Python

I am a beginner and will challenge Python. Postscript: I made it into Python3 format.

environment

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!")

variable

Assign 10 to the variable.

Python


val_int = 10
val_float = 1.23
val_boolean = True

True and False have uppercase letters.

Multiple assignment

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

list

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

dictionary

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

comment

1-line comment

Use # for comments.

Python


#1 line comment

Multi-line comment

This is a multi-line comment.

Python


"""
It's a comment, oh oh oh oh
"""

Four arithmetic operations

I will calculate.

Python


hoge = 100 + 2200
hoge = hoge / 100
hoge = hoge * 2

print hoge # 46

Factorial

Python


hoge = 10 ** 2

print hoge # 100

for loop

loop


i = 0
for _ in range(10):
  i += 1
  print i

#output
1
2
3
4
5
6
7
8
9
10

Conditional statement if statement

How to use the if statement.

vv = 50

if vv < 100:
  vv = '00'
  
print(vv)

#output
00

elsif statement

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

Standard input

Python


h1 = input()

print(h1)

#input
10

#output
10

Standard input type

Python


h1 = input()
print(type(h1))

#input
10

#output
<class 'str'>

When entered, it will be of type str.

function

It is managed by indentation.

Python


def spam():
  hoge = 12
  return hoge
        
print(spam()) # 12

String concatenation

I was able to combine strings with +.

String concatenation


hoge = 'hoge'
print('piyo' + hoge)# piyohoge

Impressions

Thank you for your hard work (☝՞ ਊ՞)

Recommended Posts

Beginners practice Python
Python beginner's note
Python Beginner's Guide (Functions)
Python beginners organize heapsort
Python beginners touch Pytorch (3)
python textbook for beginners
Python Dictionary Beginner's Guide
Python beginners touch Pytorch (1)
Python beginners touch Pytorch (2)
Merge Nodes-Houdini Python Practice
Python Beginner's Guide (Introduction)
OpenCV for Python beginners
Learning flow for Python beginners
Python
About python beginner's memorandum function
Python3 environment construction (for beginners)
3 Reasons Beginners to Start Python
Python #function 2 for super beginners
Python beginners organize bubble sort
Python Beginner's Guide (Variables / Arrays)
Basic Python grammar for beginners
100 Pandas knocks for Python beginners
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
■ Kaggle Practice for Beginners --Introduction of Python --by Google Colaboratory
Practice! !! Introduction to Python (Type Hints)
Python Exercise for Beginners # 2 [for Statement / While Statement]
Python for super beginners Python # dictionary type 1 for super beginners
Machine learning summary by Python beginners
Python #index for super beginners, slices
Predictive Statistics (Practice Simple Regression) Python
<For beginners> python library <For machine learning>
Python #len function for super beginners
Beginners use Python for web scraping (1)
# 2 Python beginners challenge AtCoder! ABC085C --Otoshidama
Algorithm (segment tree) in Python (practice)
Run unittests in Python (for beginners)
Memorandum of beginners Python "isdigit" movement
Beginners use Python for web scraping (4) ―― 1
Python #Hello World for super beginners
Python for super beginners Python # dictionary type 2 for super beginners
python beginners tried to find out
Learn the basics of Python ① Beginners
kafka python
numpy practice 1
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python comprehension
Python technique
INSERT into MySQL with Python [For beginners]
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python tips
[Python] Minutes of study meeting for beginners (7/15)
(Bad) practice of using this in Python
python function ①