찾다
백엔드 개발파이썬 튜토리얼일 - CSV 파일, ASCII, 문자열 방법

Day - CSV file, ASCII, String methods

CSV(쉼표로 구분된 값):

CSV 파일은 행을 나타내며 행 내의 각 값은 쉼표로 구분됩니다.
CSV 파일은 Excel과 비슷해 보이지만 Excel 파일은 Excel 소프트웨어에서만 열립니다.
CSV 파일은 모든 운영체제에서 사용됩니다.

CSV 파일은 다음 두 가지 형식으로 열 수 있습니다.

f =open("sample.txt", "r")

with open("sample.txt",’r’) as f:

읽어보기
읽기 위해 파일을 엽니다. 파일이 존재해야 합니다.
와-쓰세요
쓰기 위해 파일을 엽니다. 새 파일을 만들거나 기존 파일을 덮어씁니다.
rb-읽기 바이너리
이는 이미지, 비디오, 오디오 파일, PDF 또는 텍스트가 아닌 파일과 같은 바이너리 파일을 읽는 데 사용됩니다.

store.csv

Player,Score
Virat,80
Rohit,90
Dhoni,100
import csv
f =open("score.csv", "r")
csv_reader = csv.reader(f)
for row in csv_reader:
    print(row)
f.close()

['Player', 'Score']
['Virat', '80']
['Rohit', '90']
['Dhoni', '100']

ASCII:
ASCII는 American Standard Code for Information Interchange를 의미합니다.

ASCII 테이블:
48-57 - 숫자(숫자 0~9)
65-90 - A-Z(대문자)
97-122 - a-z(소문자)

ASCII 테이블을 사용한 패턴 프로그램:

for row in range(5):
    for col in range(row+1):
        print(chr(col+65), end=' ')
    print()
A 
A B 
A B C 
A B C D 
A B C D E 
for row in range(5):
    for col in range(5-row):
        print(chr(row+65), end=' ')
    print()
A A A A A 
B B B B 
C C C 
D D 
E 

for 루프 사용:

name = 'pritha'
for letter in name:
    print(letter,end=' ')

P r i t h a

while 루프 사용:

name = 'pritha'
i=0
while i<len print i>





<pre class="brush:php;toolbar:false">P r i t h a

문자열 메서드:
1. 대문자로 표시()
Python의 capitalize() 메서드는 문자열의 첫 번째 문자를 대문자로 변환하고 다른 모든 문자는 소문자로 만드는 데 사용됩니다.

txt = "hello, and welcome to my world."
x = txt.capitalize()
print (x)

Hello, and welcome to my world.

ASCII 테이블을 사용하여 대문자 프로그램 작성:

txt = "hello, and welcome to my world."

first = txt[0]
first = ord(first)-32
first = chr(first)

print(f'{first}{txt[1:]}')
Hello, and welcome to my world.

2.casefold()
Python의 casefold() 메서드는 문자열을 소문자로 변환하는 데 사용됩니다.

txt = "Hello, And Welcome To My World!"
x = txt.casefold()
print(x)
hello, and welcome to my world!

ASCII 테이블을 사용하여 케이스폴더 프로그램 작성:

txt = "Hello, And Welcome To My World!"
for letter in txt:
    if letter>='A' and letter





<pre class="brush:php;toolbar:false">hello, and welcome to my world!

3.count()
Python의 count() 메소드는 문자열 내에서 하위 문자열의 발생 횟수를 계산하는 데 사용됩니다.

txt = "I love apples, apple is my favorite fruit"
x = txt.count("apple")
print(x)

2

주어진 키에 대한 카운트 프로그램 작성:

txt = "I love apples, apple is my favorite fruit"
key="apple"
l=len(key)
count=0
start=0
end=l
while end<len if txt count start end else: print>





<pre class="brush:php;toolbar:false">2

주어진 키가 처음 나타나는 경우 프로그램 작성:

txt = "I love apples, apple is my favorite fruit"
key="apple"
l=len(key)
start=0
end=l
while end<len if txt print break start end>





<pre class="brush:php;toolbar:false">
7

주어진 키가 마지막으로 발생하도록 프로그램 작성:

txt = "I love apples, apple is my favorite fruit"
key="apple"
l=len(key)
start=0
end=l
final=0
while end<len if txt final="start" start end else: print>





<pre class="brush:php;toolbar:false">15

작업:

for row in range(4):
    for col in range(7-(row*2)):
        print((col+1),end=" ") 
    print()

1 2 3 4 5 6 7 
1 2 3 4 5 
1 2 3 
1 
for row in range(5):
    for col in range(5-row):
        print((row+1)+(col*2),end=" ") 
    print()
1 3 5 7 9 
2 4 6 8 
3 5 7 
4 6 
5 

위 내용은 일 - CSV 파일, ASCII, 문자열 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
목록과 배열 사이의 선택은 큰 데이터 세트를 다루는 파이썬 응용 프로그램의 전반적인 성능에 어떤 영향을 미칩니 까?목록과 배열 사이의 선택은 큰 데이터 세트를 다루는 파이썬 응용 프로그램의 전반적인 성능에 어떤 영향을 미칩니 까?May 03, 2025 am 12:11 AM

forhandlinglargedatasetsinpython, usenumpyarraysforbetterperformance.1) numpyarraysarememory-effic andfasterfornumericaloperations.2) leveragevectorization foredtimecomplexity.4) managemoryusage withorfications data

Python의 목록 대 배열에 대한 메모리가 어떻게 할당되는지 설명하십시오.Python의 목록 대 배열에 대한 메모리가 어떻게 할당되는지 설명하십시오.May 03, 2025 am 12:10 AM

inpython, listsusedyammoryAllocation과 함께 할당하고, whilempyarraysallocatefixedMemory.1) listsAllocatemememorythanneedInitiality.

파이썬 어레이에서 요소의 데이터 유형을 어떻게 지정합니까?파이썬 어레이에서 요소의 데이터 유형을 어떻게 지정합니까?May 03, 2025 am 12:06 AM

Inpython, youcansspecthedatatypeyfelemeremodelerernspant.1) usenpynernrump.1) usenpynerp.dloatp.ploatm64, 포모 선례 전분자.

Numpy 란 무엇이며 Python의 수치 컴퓨팅에 중요한 이유는 무엇입니까?Numpy 란 무엇이며 Python의 수치 컴퓨팅에 중요한 이유는 무엇입니까?May 03, 2025 am 12:03 AM

numpyissentialfornumericalcomputinginpythonduetoitsspeed, memory-efficiency 및 comperniveMathematicaticaltions

'연속 메모리 할당'의 개념과 배열의 중요성에 대해 토론하십시오.'연속 메모리 할당'의 개념과 배열의 중요성에 대해 토론하십시오.May 03, 2025 am 12:01 AM

contiguousUousUousUlorAllocationScrucialForraysbecauseItAllowsOfficationAndFastElementAccess.1) ItenableSconstantTimeAccess, o (1), DuetodirectAddressCalculation.2) Itimprovesceeffiency theMultipleementFetchespercacheline.3) Itsimplififiesmomorym

파이썬 목록을 어떻게 슬라이스합니까?파이썬 목록을 어떻게 슬라이스합니까?May 02, 2025 am 12:14 AM

slicepaythonlistisdoneusingthesyntaxlist [start : step : step] .here'showitworks : 1) startistheindexofthefirstelementtoinclude.2) stopistheindexofthefirstelemement.3) stepisincrementbetwetweentractionsoftortionsoflists

Numpy Array에서 수행 할 수있는 일반적인 작업은 무엇입니까?Numpy Array에서 수행 할 수있는 일반적인 작업은 무엇입니까?May 02, 2025 am 12:09 AM

NumpyAllowsForVariousOperationsOnArrays : 1) BasicArithmeticLikeadDition, Subtraction, A 및 Division; 2) AdvancedOperationsSuchasmatrixmultiplication; 3) extrayintondsfordatamanipulation; 5) Ag

파이썬으로 데이터 분석에 어레이가 어떻게 사용됩니까?파이썬으로 데이터 분석에 어레이가 어떻게 사용됩니까?May 02, 2025 am 12:09 AM

Arraysinpython, 특히 Stroughnumpyandpandas, areestentialfordataanalysis, setingspeedandefficiency

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.