💻
Albert's Til
GitHub
  • 매일매일 조금씩 성장하기
    • README
    • CS
      • Network
      • HTTP
        • NO-CACHE
      • 오류 코드
      • ORM 도구
      • Design Pattern
        • CQRS Pattern
          • Event Sourcing and CQRS pattern
        • Builder Pattern
    • DB
      • MySQL
        • Timeline
        • Pagination
        • Index
        • Database Performance Optimization Strategies
        • B+ tree
        • MySQL Connectors VS MySQL Shell(Scripting) VS MySQL Workbench
        • MySQL Storage Engine Architecture
      • Normalization & Denormalization
      • JPA
        • @Transactional
        • Why JPA?
        • About JPA
        • N+1 Issue
        • Index
        • ElementCollection&CollectionTable
        • orphanRemoval
        • CascadeType
        • Use Subselect
        • Dynamic Instance Creation
        • Paging
        • Order
        • Spefication
        • mappedBy
      • MongoDB
        • ObjectId
      • Why MySQL?
      • ACID properties of transactions
      • Between JPA and JDBC
      • Identifiers in Hibernate/JPA
    • Java
      • Jackson de/serialize
      • Collections.singletonList() vs List.of()
      • Manage dependencies in Gradle
      • Logging Level
      • Bean Validation
      • JVM Internals
        • Threads
          • Frame
        • Shared Between Threads
          • Classloader
            • Class Loader Hierarchy
            • Loading Linking Initialization
      • Java Collection Framework
      • Annotation
      • Generic
      • 디미터 법칙
    • Spring
      • Caching
      • Spring Integration Overview
        • ThreadPollTaskExecutor
        • Messaging Bridge
        • Channel Adapter
        • Poller
        • Configuration and @EnableIntegration
        • Message Endpoints
        • Message Channels
      • HATEOAS
      • @Autowired vs Constructor Dependency Injection
      • Spring Security
        • JWT 토큰 사용한 인가
        • OAuth 2 Login
        • OAuth 2 인증
        • 인가
        • 인증
        • PasswordEncoder
      • IoC Container
      • Filter,Interceptor,AOP,Argument Resolver
      • Spring Annotation
      • About Spring
    • Kafka
      • Error Channel
    • Infra
      • Scale Up || Scale Out
      • Docker
        • Dockerfile
        • Docker Hub Deploy
        • Command
      • Cloud 유형
        • Infrastructure as a Service
        • Platform as a Service
        • Software as a Service
      • 무중단 배포
        • 엔진엑스(Nginx)
      • 코드 자동 배포
        • Technical
      • AWS EC2
        • PEM(Privacy Enhanced Mail) 키
      • AWS RDS
      • AWS S3
    • CodeSquad
      • Spring Boot Project 1주차 회고
      • Spring Boot Project 2주차 회고
      • Spirng Boot Project 3주차 회고
      • Spring Boot Project 4주차 회고
    • Foody Moody 프로젝트
      • Query Performance Comparison
      • HeartCount Asynchronous Issue
      • DeferredResult
      • ResponseBodyEmitter
      • SseEmitter (Spring)
      • Server-Sent Events (SSE)
      • 기술 스택 적용 이유
      • NO-CACHE(HTTP)
      • Transactional
    • DDD
      • AggregateId
    • Test
      • RestAssured
    • Coding and Algorithmic Problems
      • 819. Most Common Word
      • 344. Reverse String
      • 125. Valid Palindrome
      • 937. Reorder Data in Log Files
    • Node
      • Async... Await...
      • Custom Transactional Decorator Challenger
    • Python
      • Python Basic Grammar
        • Comments and Input/Output
        • Variable
        • Data type
        • Operations and syntax
        • List,Tuple,Dictionary,Set
        • Function
        • Conditional statement
        • Loop
    • HTML
      • HTML Basic
      • HTML Basic Tags
      • HTML Form Tags
      • HTML Table Tags
    • CSS
      • CSS Basic
      • CSS Practice
Powered by GitBook
On this page
  • 변수 이름
  • 변수의 타입
  • 변수 삭제
  • 참조

Was this helpful?

  1. 매일매일 조금씩 성장하기
  2. Python
  3. Python Basic Grammar

Variable

변수

Last updated 12 months ago

Was this helpful?

변수는 어떤 값이 있는 위치를 가리킨다.

python에서 변수는 값을 직접 저장하는 것이 아니라 객체에 대한 참조(주소)를 저장합니다. 변수 간의 할당은 실제 값을 복사하는 것이 아니라 객체에 대한 참조를 복사하는 것입니다.

x = 10
y = x
z = y

x = 20

"""
결과:
x = 20
y = 10
z = 10
"""

변수 이름

  1. 알파펫(대소문자), 숫자, 인더스코어(_) ⭕️

  2. 숫자로 시작 ❌

  3. 파이썬의 키워드 (예: if, else, while 등) ❌

  4. 대소문자 구분 ⭕️

# 올바른 변수 이름
student_name = "Alice"
age = 20
_gpa = 3.5
course_101 = "Mathematics"
EmployeeID = 12345
total_sales_2024 = 500000
isEnrolled = True

# 잘못된 변수 이름
2nd_place = "Bob"  # 숫자로 시작 ❌
class = "Physics"  # 파이썬 키워드 사용 ❌
first-place = 1    # 하이픈(-) 사용 ❌

변수의 타입

type() 함수를 사용하여 타입 확인

age = 10
print(type(age)) # 출력: <class 'int'>

dir() 함수를 사용하여 해당 타입이 가진 속성과 메서드를 확인

# 문자열 타입의 속성과 메서드 확인
print(dir(str))

['capitalize',    # 첫 글자를 대문자로 변환
 'center',        # 문자열을 지정된 너비로 가운데 정렬
 'count',         # 부분 문자열의 등장 횟수를 반환
 'encode',        # 문자열을 지정된 인코딩으로 변환
 'find',          # 부분 문자열을 찾아서 인덱스를 반환 (없으면 -1)
 'format',        # 문자열 포맷팅
 'index',         # 부분 문자열을 찾아서 인덱스를 반환 (없으면 예외 발생)
 'isalnum',       # 모든 문자가 영숫자인지 여부를 확인
 'isalpha',       # 모든 문자가 알파벳인지 여부를 확인
 'isdigit',       # 모든 문자가 숫자인지 여부를 확인
 'islower',       # 모든 문자가 소문자인지 여부를 확인
 'isupper',       # 모든 문자가 대문자인지 여부를 확인
 'join',          # 문자열의 모든 항목을 연결하여 하나의 문자열로 반환
 'lower',         # 모든 문자를 소문자로 변환
 'lstrip',        # 문자열 왼쪽의 공백을 제거
 'replace',       # 부분 문자열을 다른 문자열로 대체
 'rfind',         # 부분 문자열을 오른쪽에서 찾아서 인덱스를 반환 (없으면 -1)
 'rsplit',        # 오른쪽에서부터 분할
 'rstrip',        # 문자열 오른쪽의 공백을 제거
 'split',         # 구분자를 기준으로 문자열을 분할하여 리스트로 반환
 'startswith',    # 문자열이 특정 접두사로 시작하는지 여부를 확인
 'strip',         # 문자열 양쪽의 공백을 제거
 'title',         # 모든 단어의 첫 글자를 대문자로 변환
 'upper',         # 모든 문자를 대문자로 변환
 ...]         

변수 삭제

del 키워드를 사용하여 변수를 삭제

del variable # NameError

참조

ChatGPT

견고한 파이썬