Intermediate Python 2. String operations 영어 파이썬 코딩영어
LC training(2:55) - It's the same thing but if you ask me the first one is just so much readable and i'm not really sure that it's worth the performance gain here And as Python changes overtime these are things like subtle things like these There really are going to change by Python even version sometimes So in some senses this they might be like the difference is probably just extremely negligible you'll get away with it But the difference is when say you've got a list of strings or really anything and you want to just print them out as a string print that list as a string of course you could do string names and just print that But let's say instead you actually want to just print the list of the names as a string So that might look something like let me just comment this out whoops comment this out and that might look like whoops not again um We will join just as a comma dot join and then names is a list so we're fine Let's run that and in fact let's do comma space There we go so we've got Jeff Garry Jill Samantha okay So that that works Is it easily readable? If you know how join works then sure it's readable But if you don't know how join works that's not readable at all But when it comes to concatenating strings join is preferable when you're joining more than two strings Some people will argue that maybe it's more than like some sort of strings like when the processing changes But i think it is a general rule of thumb if you're going to concatenate and truly concatenate because actually what we're doing here we are concatenated but we're still actually kind of doing the wrong thing in both of these examples I'll show you the right things soon enough But probably this isn't even the right way to go about it But if you're concatenating two or more than two not two two or more so basically all concatenation no If you're in concatenating more than two strings you probably should be using join purely because it's going to scale better It's going to use less processing
Summary & Code results -
string data를 처리하다 보면, concatenation은 어떻게 하지? formatting은 어떻게 하지? 하는 의문이 생깁니다. 가장 기본이 되는 기능이기도 하지만, 이 두 개의 function 용법을 알고나면 앞으론 string을 갖고선 얼마든지 scaling이 가능한 코딩역량을 갖추게 되십니다. join()과 format() 입니다.
names = ['Jeff', 'Gary', 'Jill', 'Samantha']
for name in names:
print('Hello there, ' + name)
print(' '.join(['Hello there,', name]))
print(', '.join(names)) #scales better
import os
location_of_files = 'C:\\Users\\USER\\Desktop\\Intermediate-Tutorials'
file_name = 'example.txt'
print(location_of_files + '\\' + file_name)
with open(os.path.join(location_of_files, file_name)) as f:
print(f.read())
who = 'Gary'
how_many = 12
# Gary bought 12 apples today!
print(who, 'bought', how_many, 'apples today!')
print('{} bought {} apples today!'.format(who, how_many)) #the correct way of string formatting
원본 비디오: https://www.youtube.com/watch?v=jA5LW3bR0Us&list=PLQVvvaa0QuDfju7ADVp5W1GF9jVhjbX-_&index=3&t=5s
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Intermediate Python 2. String operations 영어 파이썬 코딩영어», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.