It is a personal memo
python3
・ Raw_input ()
Keyboard input (python2)
input () for python3
n = input() n = int(input())
・ .Strip ()
Remove whitespace characters (spaces, tabs, newlines)
input().strip()
・ Sprit ()
Makes an array separated by the specified characters.
If not specified in (), separate with a space or TAB
input().split()
・ STDIN
Keyboard entered value
Standard input
・ Difference Difference difference of the two numbers (first - second).
・ Product multiplication product of the two numbers.
・ ʻA // b` division. Returns the quotient as an integer Truncate after the decimal point
・ For statement
for variable in sequence
n = int(raw_input())
for i in range(n):
print(i*i)
・ ` Lange ` i<n from i = 0 n is not included.
range(3) = [0,1,2]
・ Leap Day leap year We add a Leap Day on February 29.
・ Intercalary day The day it was plugged in The leap day is an extra, or intercalary day.
・ Evenly divided by ~ Divisible by The year can be evenly divided by 4, is a leap year.
・ ʻIf statement` Required ":" after if, elif, else.
・ Sum (array)
Calculate the total value
list = range(5)
print(sum(list))
・ Str ()
Convert to string
n = int(input())
a=""
for i in range(n):
a =a+str(i+1)
print(a)
#output
a=12345~
・ Arithmetic operations Arithmetic operator. +-*%
・ Runner-up second place you are required to find the runner-up score.
・ (Lambda variable: processing) (argument)
Lambda function
You can create a function in one line (equivalent to def)
(lambda variable: processing) (argument)
└ Assign arguments to processing
└ Multiple arguments are possible. Enter a variable in the ranking process.
print((lambda a,b,c:a*100+b*10+c*1)(1,2,3))
#output
123
・ Map (function, array)
map function
Execute a function for each element of the array.
The output is a map object
→ Convert to list object with list (map ())
-Convert an array to an integer using the map function map = (int, array)
arr = map(int, input().split())
・ X ** y
Exponentiation. x to the yth power
100 = 0 103 = 1000
・ Set ()
Remove duplicate values from array
set type
arr=[2,3,6,6]
print(set(arr))
{2,3,6}
・ Sorted ()
Arrange the array in ascending order
Extract the nth largest value sorted()[-n]
#Extract the second largest value
arr=[2,3,6,6,5]
sorted(set(arr))[-2]
#output
5
・ Order their names alphabetically Arrange in alphabetical order order their names alphabetically and print each one on a new line.
Recommended Posts