[udemy] python 부트캠프 _ section 1_ 파이썬 변수를 사용한 데이터 관리

Dreamer ·2022년 8월 6일
0
post-thumbnail

1. print()

print("Hello python") 
  • print() : 원하는 내용을 출력할 때 사용하는 함수
  • 따옴표의 의미 : 프로그래밍 코드가 아니라는 것을 표시하기 위함. 이 내용은 텍스트(strings)이고 출력하고자 하는 내용임을 알림.
print("print('what to print')")
  • 큰 따옴표를 안에 다른 따옴표를 사용하려고 하면, 작은 따옴표를 사용해야 한다.
  • "A"B"c" -> A,C는 string, B는 code로 인식하게 된다.
print("Hello world!\n Hello world!\n Hello world!")
  • \n : 문장의 다음줄 (즉, enter키)
  • print() 한 번으로 세 문장을 출력함
print("Hello " +"Angela") 
print("Hello" + " Angela")
print("Hello" + " " + "Angela")
  • output : Hello Angela
  • python에선 공백이 중요함.
  • Python에선 코드 사이의 "들여쓰기"가 중요함.
  • Syntax Error: 문법 오류
  • Indentation Error : 들여쓰기 오류
print("Day 1 - String Manipulation")
print('String Concatenation is done with the "+" sign.')
print('e.g. print("Hello " + "world")')
print("New lines can be created with a backslash and n.")

2. input()

input(prompt)
  • 괄호 안에는 사용자에게 전달할 문장이 들어감.
  • print() 함수와 비슷해보이지만, 문장을 출력하는 것이 아니라 문장 or 단어를 입력 받는다.
  • 사용자에게서 데이터를 입력 받으면, input(prompt) 코드 문장을 대체하게 된다.
print("Hello " + input("what is your name?"))
  • input() will get user input in console.
  • Then print() will print the word "Hello" and the user input.

3. 주석

  • 주석 다는 법 : command + /
  • 주석 취소 하는 법 : command + z

4. len

print(len(input("What is your name?")))
  • output : 사용자에게서 이름을 입력받아 그 이름의 글자수를 출력함.
  • len() : input 받은 string의 길이를 추출해 줌.
  • if input was "Jack"
  • 1st : print(len("Jack"))
  • 2nd : print(4)

5. variables

name = input("What is your name?")
print(name)
  • 일반적으로 input으로 받은 값은 사라지지만, name이라는 변수에 저장하게 되면 언제든 데이터를 불러올 수 있다.
name = input("What is your name?")
lenght = len(name)
print(lenght)
  • 데이터들은 전부 name 변수와 연결되어 코드 어느 곳에서도 사용할 수 있게 된다.

6. variables name

  • 파이썬에서 변수는 하나의 단위여야 하고, 단어를 분리한다면 밑줄을 사용한다.
  • 숫자가 변수명의 처음 시작을 차지할 수 없다.
  • 함수로 사용되는 단어는 변수명으로 사용하지 말아야 한다.(eg.input, print)
  • 변수에 일관성이 있어야 한다. 코드에 이름 오류가 발생한다면, 변수명에 오타가 있는 것임.

7. last project

print("Welcome to the Band Name Generator.")
city_name = input("What's the name of the city you grew up in?\n")
print(city_name)
pet_name = input("What is the name of your pet?\n")
print(pet_name)
print("This is your band name : "+ city_name + " " + pet_name)
profile
To be a changer who can overturn world

0개의 댓글