πŸ“—
JunegLee's TIL
  • TIL
  • python
    • class
    • String Basic
    • regularExpression
    • String function
    • Generator
    • String format
    • getset
    • module
    • while
    • numpy
    • print()
    • matplotlib
    • for
    • Boolean
    • tuple
    • package
    • input(variable)
    • list
    • if
    • file
    • type()
    • pandas
    • function
    • dictionary
    • ꡬ문 였λ₯˜μ™€ μ˜ˆμ™Έ
    • builtinFunction
    • Constructor
  • algorithm
    • sort
      • mergeSort
      • insertionSort
      • bubbleSort
      • heapSort
      • quickSort
      • selectionSort
    • recursion
    • Greedy
    • DepthFirstSearch
    • basic
      • DataStructure
    • hash
    • BreadthFirstSearch
  • tensorflow
    • keras
      • layers
        • Flatten
        • Flatten
        • Dense
        • Dense
        • Conv2D
        • Conv2D
    • tensorflow1x
    • tensorflow2x
  • DB
    • setting
    • join
    • subQuery
    • overview
  • deep-learning
    • neuralNetwork
    • perceptron
    • neuralNetworkLearning
    • convolution neural network
    • Gradient Descent
    • Linear Regression
    • backPropagation
    • logistic regression
    • overview
  • textPreprocessing
    • overview
  • java
    • basics
      • generic
      • Variable
      • String
    • theory
      • Object Oriented Programing
  • NLP
    • Embedding
    • Natural Language Processing
Powered by GitBook
On this page
  • λ³€μˆ˜ variable
  • μ›μ˜ λ‘˜λ ˆμ™€ 넓이 κ΅¬ν•˜κΈ°
  • 파이썬 μžλ£Œν˜• νŠΉμ§•
  • 볡합 λŒ€μž… μ—°μ‚°μž
  • λ¬Έμžμ—΄ λ³΅ν•©λŒ€μž… μ—°μ‚°μž(λ§ˆμ°¬κ°€μ§€λ‘œ += 와 *= μ‚¬μš©κ°€λŠ₯ )
  • μ‚¬μš©μž μž…λ ₯ : input()
  • input() ν•¨μˆ˜μ˜ μž…λ ₯ μžλ£Œν˜•
  • λ¬Έμžμ—΄ 숫자둜 λ°”κΎΈκΈ°
  • ValueError μ˜ˆμ™Έμ²˜λ¦¬
  • 숫자둜 λ¬Έμžμ—΄ λ°”κΎΈκΈ° : str

Was this helpful?

  1. python

input(variable)

λ³€μˆ˜ variable

  • 영문 λ¬Έμžμ™€ 숫자λ₯Ό μ‚¬μš©ν• μˆ˜ 있음

  • λŒ€μ†Œλ¬Έμžλ₯Ό ꡬ뢄

  • λ¬ΈμžλΆ€ν„° μ‹œμž‘ν•˜λ©°, μˆ«μžλΆ€ν„° μ‹œμž‘ν•˜λ©΄ μ•ˆλœλ‹€

  • _(밑쀄 문자)둜 μ‹œμž‘ν•  수 μžˆλ‹€

  • 특수문자 μ‚¬μš©ν•  수 μ—†λ‹€

  • 파이썬 ν‚€μ›Œλ“œ(if, for)λŠ” λ³€μˆ˜λ‘œ μ‚¬μš©ν•  수 μ—†λ‹€

  • λ³€μˆ˜ = κ°’

    pi = 3.14159265
    print(pi)

μ›μ˜ λ‘˜λ ˆμ™€ 넓이 κ΅¬ν•˜κΈ°

pi = 3.14159265
r = 10

print("μ›μ£Όμœ¨ = ", pi)
print("λ°˜μ§€λ¦„ = ", r)
print("μ›μ˜ λ‘˜λ ˆ = ", 2 * pi * r)
print("μ›μ˜ 넓이 = ", pi * r ** 2)

파이썬 μžλ£Œν˜• νŠΉμ§•

  • νŒŒμ΄μ¬μ€ C, java 처럼 λ³€μˆ˜μ˜ μžλ£Œν˜•μ— λŒ€ν•΄ 미리 μ„ μ–Έν•˜μ§€ μ•Šκ³ 

    μ—¬λŸ¬ μ’…λ₯˜μ˜ μžλ£Œν˜•μ„ 넣을 수 μžˆλŠ” μœ μ—°μ„±μ„ κ°€μ§€κ³  μžˆλ‹€

    a = "λ¬Έμžμ—΄"
    a = True
    a = 10
    print(a) # 10

볡합 λŒ€μž… μ—°μ‚°μž

μ½”λ“œ

μ„€λͺ…

+=

숫자 λ§μ…ˆ ν›„ λŒ€μž…

-=

숫자 λΊ„μ…ˆ ν›„ λŒ€μž…

*=

숫자 κ³±μ…ˆ ν›„ λŒ€μž…

/=

숫자 λ‚˜λˆ—μ…ˆ ν›„ λŒ€μž…

%=

숫자의 λ‚˜λ¨Έμ§€λ₯Ό κ΅¬ν•œ ν›„ λŒ€μž…

**=

숫자 제곱 ν›„ λŒ€μž…

num = 100
num += 10
num -= 20
num *= 3
print("num κ²°κ³Όκ°’ : ", num) # 270

λ¬Έμžμ—΄ λ³΅ν•©λŒ€μž… μ—°μ‚°μž(λ§ˆμ°¬κ°€μ§€λ‘œ += 와 *= μ‚¬μš©κ°€λŠ₯ )

String = "μ•ˆλ…•ν•˜μ„Έμš”" 
String += "!"
String += "!"
print("String κ²°κ³Ό : ", String) # μ•ˆλ…•ν•˜μ„Έμš”!!

μ‚¬μš©μž μž…λ ₯ : input()

String = input("인사말을 μž…λ ₯ν•˜μ„Έμš”> ")
print(String)

input() ν•¨μˆ˜μ˜ μž…λ ₯ μžλ£Œν˜•

number = input("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”> ")
print(number) # 12345
print(type(number)) # κ²°κ³Όκ°’ :  Str
  • 무엇을 μž…λ ₯ν•˜μ—¬λ„ 무쑰건 λ¬Έμžμ—΄ μžλ£Œν˜•μ΄λ‹€.

λ¬Έμžμ—΄ 숫자둜 λ°”κΎΈκΈ°

String_a = input("μž…λ ₯A > ")
int_a = int(String_a)
int_fa = float(String_a)

String_b = input("μž…λ ₯B > ")
int_b = int(String_b)
int_fb = float(String_b)
  • 예제 A : 123 B : 45

    print("λ¬Έμžμ—΄ 자료 : ", String_a + String_b) # 12345
    print("숫자 자료 :" , int_a + int_b) # 168
    print("float 자료 :" , int_fa + int_fb) # 168.0

ValueError μ˜ˆμ™Έμ²˜λ¦¬

  1. μˆ«μžκ°€ μ•„λ‹Œ 것을 숫자둜 λ³€ν™˜ν•˜λ €κ³  ν• λ•Œ

    int("μ•ˆλ…•ν•˜μ„Έμš”")
  2. μ†Œμˆ˜μ μ΄ μžˆλŠ” 숫자 ν˜•μ‹μ„ λ¬Έμžμ—΄ int() ν•¨μˆ˜λ‘œ λ³€ν™˜ν•˜λ €κ³  ν• λ•Œ

    int("52.273")

숫자둜 λ¬Έμžμ—΄ λ°”κΎΈκΈ° : str

output_a = str(52)
output_b = str(52.273)
print(type(output_a), output_a) # <class 'str'> 52
print(type(output_b), output_b) # <class 'str'> 52.273
PreviouspackageNextlist

Last updated 4 years ago

Was this helpful?