String Concatenation and Formatting - Intermediate Python Programming p.2

preview_player
Показать описание
Welcome to part 2 of the intermediate Python programming tutorial series. In this part, we're going to talk about strings. Strange that we find such a topic in an intermediate series, but it's probably one of the most common things done improperly.

Рекомендации по теме
Комментарии
Автор

Always enjoy your work Sentdex. Thanks. No matter how much I learn, I always enjoy a walk back to the basics.

FullSpectrumSurvival
Автор

this looks even cleaner in my opinion. Use the "f" tag.

names = ['Jeff', 'Gary', 'Jill', 'Samantha']

for name in names:
print(f'Hello there, {name}')

IamJakoby
Автор

animals = (bird, cat, dog)
print("The {} was eaten by the {} which was chased off by the {}".format(bird, cat, dog)
Is the same as...
print("The {} was eaten by the {} which was chased off by the {}".format(*animals)
The * unloads the list, tuple..etc.. saves on space, especially when doing SQL.

kyleconn
Автор

The indexes can be useful in some circumstances. If your string was going to be 'Gary bought 12 apples. Gary ate one on the way home.' You would use indices 0, 1, 0 and wouldn't have to include name twice in the format list.

TangoFoxtrotWhiskey
Автор

Please keep uploading videos, your lessons are amazing, short and straight to the point, and thanks for them =)

Credin
Автор

Thank you very much, learning python with you is a joy for evreyone.

rotrose
Автор

This guy is going to break his keyboard eventually

hirok
Автор

There's a neat little function called f-strings now. I think it's pretty readable. A simple example:


time_of_day = 'morning'
animal_type = 'bird'

sentence = f'There was a {animal_type} at my window this {time_of_day}'

print(sentence)

tweede
Автор

hey man, love your python basics videos :D. I am self learning programming and stumbled upon your channel was intrigued by the simplicity of python so got hooked on them. I am atm learning about tuples and lists and so far learned about conditions, loops, function definitions and some very basic stuff. But that is the syntax side of things, I want to become a complete programmer and to do that I need to solve problems right, so is there any website that has small problems which let me practice my logic muscles? Love you :D

hammad.ahmed
Автор

Enjoy your python series very much. Very excited to get a better way to do things. Thank you

rotrose
Автор

This has got to be the most #entertaining# programming video ever made! Great info, with a bonus of smart comedy?!? "upgrade to 3": YES!

MrTbill
Автор

If you need to use a variable multiple times you can name the curly brace placeholders like
print("{a} + {a} = {b}"'.format(a=1, b=2))

christoffaloffagus
Автор

Is there any way to adjust your sound recording so that your typing isn't so loud? Thanks, great videos!

subwaysnacker
Автор

index is still useful if you want the same variable in 2 places like 'folder/{0}/{1}/{0}'.format(folder1, folder2)

danielismyhandle
Автор

You make great videos!
They help me a lot in my programs

dylanriley
Автор

Pretty sure you don't have to use index numbers when formatting in Python 2. Also, you can name your args when using format for better readability. For example, "hello there {name}".format(name="john")

johnnysim
Автор

Hi, great video! I have a practical question, how to you comment all the lines at the same time?

karinwiberg
Автор

4:10 Another approach using list unpacking and the sep argument of print:


print(*names, sep=', ')

__gavin__
Автор

Regarding your first example, is print('Hello there, ' + name) really less efficient than print(' '.join(['Hello there, ', name]))? I mean the latter has to construct a new list for each name.

Majskolvenz
Автор

This is amazing, thank you!

keep making these please.

lucaswiese
join shbcf.ru