연산자 설명 예제
+ 덧셈 2 + 4 == 6
뺄셈 2 - 4 == -2
* 곱셈 2 * 4 == 8
** 지수 2 ** 4 = 16
/ 나눗셈 2 / 4.0 == 0.5
//  나눗셈(소수점 버림) 2 / 4.0 == 0.0
% 문자열 삽입 또는 나머지 2 % 4 == 2
< 작다 4 < 4 == False
> 크다 4 > 4 == False
<= 작거나 같다 4 <= 4 == True
>=  크거나 같다 4 >= 4 == True
== 같다 4 == 5 == False
!= 다르다 4 != 5 == True
( ) 소괄호(parenthesis) len('hi') == 2
[ ] 리스트 대괄호(bracket) [1,3,4]
{ } 딕션어리 중괄호(brace) {'x' : 5, 'y' : 10}
@ 장식자 또는 데코레이터(decorator) @classmethod
, 쉼표(comma) range(0,10)
: 쌍점(colon) def X():
. 점(dot) self.x = 10
= 대입 x = 10
; 쌍반점(semi-colon) print("hi"); print("there")
+= 더하고 대입 x = 1; x += 2
-= 빼고 대입 x = 1; x -= 2
*= 곱하고 대입 x = 1; x *= 2
/= 나누고 대입 x = 1; x /= 2
//= 나누고 대입(소수점 버림) x = 1; x //= 2
%= 나머지 대입 x = 1; x %= 2
**= 지수 대입 x = 1; x **= 2

'#Learn More Python3 the Hard Way #제드 쇼 ' 카테고리의 다른 글

# 구식 문자열 포맷  (0) 2019.07.10
#argparse  (0) 2018.10.04

 

포맷 설명 예제
%d 십진수(부동소수점 제외) "%d" % 45 == '45'
%i %d와 같음 "%i" % 45 == '45'
%o 8진수 "%o" % 1000 == '1750'
%u 부호 없는 십진수 "%u" % -1000 == '-1000'
%x 소문자 16진수 "%x" % 1000 == '3e8'
%X 대문자 16진수 "%X" % 1000 == '3E8'
%e 소문자 'e'를 쓰는 지수 표기법 "%e" % 1000 == '1.000000e+03'
%E 대문자 'e'를 쓰는 지수 표기법 "%E" % 1000 == '1.000000E+03'
%f 부동소수점 실수 "%f" % 10.34 == '10.340000'
%F %f와 같음 "%F" % 10.34 == '10.340000'
%g %f든 %e든 짧은 쪽 사용 "%g" % 10.34 == '10.34'
%G %g와 같지만 대문자 "%G" % 10.34 == '10.34'
%c 문자 "%c" % 34 == ""
%r 디버그용 repr 포맷 "%r" % int == "<type 'int'>"
%s 문자열 포맷 "%s there" % 'hi' == 'hi there'
%% 퍼센트 기호 "%g%%" % 10.34 == '10.34%'

 

'#Learn More Python3 the Hard Way #제드 쇼 ' 카테고리의 다른 글

#python #연산자  (0) 2019.07.11
#argparse  (0) 2018.10.04

[참고]

Argparse Tutorial

https://docs.python.org/3.9/howto/argparse.html#id1

https://docs.python.org/3/library/argparse.html?highlight=argparse

 

  • argparse 모듈은 커맨드 라인 인터페이스에 적용하기 쉽게 만들어진 모듈
  • argparse 모듈은 자동으로 help를 생성하고 사용자가 프로그램에 잘못된 인수를 넣으면 사용 메시지와 에러 메시지를 생성함

ArgumentParser objects

class argparse.ArgumentParser(prog=Noneusage=Nonedescription=Noneepilog=Noneparents=[]formatter_class=argparse.HelpFormatterprefix_chars='-'fromfile_prefix_chars=Noneargument_default=Noneconflict_handler='error'add_help=Trueallow_abbrev=True)

Create a new ArgumentParser object. All parameters should be passed as keyword arguments. Each parameter has its own more detailed description below, but in short they are:

  • prog - The name of the program (default: sys.argv[0])
  • usage - The string describing the program usage (default: generated from arguments added to parser)
  • description - Text to display before the argument help (default: none)
  • epilog - Text to display after the argument help (default: none)
  • parents - A list of ArgumentParser objects whose arguments should also be included
  • formatter_class - A class for customizing the help output
  • prefix_chars - The set of characters that prefix optional arguments (default: ‘-‘)
  • fromfile_prefix_chars - The set of characters that prefix files from which additional arguments should be read (default: None)
  • argument_default - The global default value for arguments (default: None)
  • conflict_handler - The strategy for resolving conflicting optionals (usually unnecessary)
  • add_help - Add a -h/--help option to the parser (default: True)
  • allow_abbrev - Allows long options to be abbreviated if the abbreviation is unambiguous. (default: True)

Changed in version 3.5: allow_abbrev parameter was added.

The following sections describe how each of these are used.

'#Learn More Python3 the Hard Way #제드 쇼 ' 카테고리의 다른 글

#python #연산자  (0) 2019.07.11
# 구식 문자열 포맷  (0) 2019.07.10

+ Recent posts