Language/Python

반응형
반응형
Language/Python

[코딩도장]08~09.불과 비교, 논리 연산자, 문자열

08. 불과 비교 논리 연산자 8.1 불과 비교 연산자 사용하기 - 기본적인 연산자는 동일하므로 생략 - 문자열 비교 >>> 'Python' == 'Python' Ture # 대소문자 불일치 : False >>> 'Python' == 'python' False - 객체 비교 # 값 비교 : True >>> 1 == 1.0 True # 객체 비교: False >>> 1 is 1.0 False - id() 함수 : 정수와 실수 객체 비교 함수 - id = 객체의 고유한 값(메모리 주소) - 이 값은 파이선을 실행하는 동안에는 계속 유지되며, 다시 실행하면 달라진다 >>> id(1) 1714767504 >>> id(1.0) 553200032 - 값 비교에는 is를 쓰지 않는다 - 변수가 있는 상태에서 다른 값..

Language/Python

[코딩도장]07.출력방법

07. 출력 방법 7.1 값 여러개 출력 >>> print(10, 20, 30) 10 20 30 >>> print('hello', 'world') hello world - sep(구분자, separator)로 값 사이에 문자 넣기 # 콤마 지정 >>> print(10, 20, 30 , sep=',') 1, 2, 3 # 빈 문자열 지정(띄어쓰기 없애기) >>> print('hello', 'world', sep='') helloworld # 특정 문자열 지정 >>> print(1000, 2000, sep='x') 1000x2000 # 줄바꿈 >>> print(10, 20, 30, sep='\n\') # 또는 print('1\n2\n3') 10 20 30 제어문자 - \n 또는 \r: 개행 ** - \t: t..

Language/Python

[코딩도장]06.변수와 입력

06. 변수와 입력 6.1 변수 만들기 - 변수이름 = 값 변수선언 규칙 - 영문문자, 숫자 사용 가능 - 대소문자 구분 - 문자부터 시작(숫자X) - _(밑줄 문자)로 시작 가능 - 특수문자 사용X - 문법 키워드 사용X(if, for, while, and, or 등) - 변수 여러개 >>> x, y, z = 10, 20, 30 >>> print(x, y, z) 10 20 30 # Error : 변수와 값의 개수가 불일치하는 경우 >>> x, y, z = 10, 20 ValueError: not enough values to unpack(expected 3, got 2) - 동일 값의 변수 여러개 x = y = z = 10 - 두 변수의 값을 바꿀 때 >>> x, y = 10, 20 >>> x, y =..

Language/Python

[코딩도장]03~05.기본문법

03. Hello, world # app.py print('Hello, world') [출력방법] - 터미널: python app.py - pycham(또는 기타 IDE): run 인터프리터 설정(Mac기준) preferences - Project:python - python interpreter - [setting버튼] - add - Base interpreter: /usr/bin/python3 선택 * 맥의 경우 보통 python3로 사용 04. 기본문법 4.1 세미콜론 - python은 세미콜론 사용 X - 세미콜론 사용해도 에러 X, 한 줄에 여러 문장을 사용할 경우 세미콜론으로 구분 4.2 주석 - # : 한줄주석, 블록주석 동일 4.3 들여쓰기 공백(스페이스)2칸, 4칸(권장), 탭 - if ..

Language/Python

[python]flask02_render_template

우선 다음과 같이 파일이 담겨 있다. [application.py] # -*- coding: utf-8 -*- from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def root(): return ''' hello ''' @app.route('/hello') @app.route('/hello/') def hello(name=None): return render_template('hello.html', name=name) @app.route('/test', methods=['POST']) def test(): return render_template('test.html', test=request.for..

Language/Python

[python]flask01

[hello01] # -*- coding: utf-8 -*- from flask import Flask app = Flask(__name__) @app.route('/') #localhost:5000으로 요청 해서 헬로월드로 리턴 def hello(): return 'Hello, World!' if __name__ == '__main__': app.run() # 결과값 * Serving Flask app "hello01" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. ..

emojiyeon
'Language/Python' 카테고리의 글 목록 (6 Page)