Python 3 Programming Tutorial: If Statement

preview_player
Показать описание
The if statement is one of the most basic forms of logic that can be introduced into your program. The idea of the if statement is to assess whether something is the case, and, if it is, then to perform the following block of code within the statement.

In this tutorial you are shown how to use the if statement in python 3.3.

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

thank you, my professor is useless since we have to do everything online and he doesnt respond

nutblunt
Автор

Thank youuuu!!!
I was trying to learn this from a kids book and got super confused with what the author was trying to say 😂
This explanation made it sound so easy XD

Sohasorouri
Автор

i am watching this in 2020 and my first code is
print("u are very useful unlike other yolutubers who bullshit")

twelfydelfy
Автор

print ("You are the best sentdex")

extro
Автор

Coffee = 2
milk = 8
sugar = 0

if Coffee > milk:
print ('too much coffee!')

if sugar > 0:
print ("Oh no! it's

if Coffee == milk:
print ("OOH that's a strong coffee..")

apriltost
Автор

You can also use negative statements like:

x = 3
y = 5

if not x == y:
print('x is not equal to y')

if not y < x:
print('y is greater than x')

I wouldn't recommend doing like that second example though as it is confusing. But just so you know, it's possible.

djleisheng
Автор

while 1==1:
print("i love you Sentdex")

amjad.m
Автор

Thank you. I needed an If conditional without the else to teach children i.e. chunk the lesson.

stephaniekimbrough
Автор

wow takes me a couple lessons foor the teacher to finish one of these but for youit takes about less than 10 minutes although i learn with 15 mins at school.
Yours is so much easier to understand. I might be saying that cause im a fastlearner but it is the truth.

arrowsverse
Автор

I figured out if statements on my own, but then I tried using multiple if statements. I ran into some problems.

BraydenDarrell
Автор

Can you make an if statement check if a given input is an integer or not?

YURTZYN
Автор

skipcount = -1
song = ['always', 'look', 'on', 'the', 'bright', 'side', 'of', 'life']

for sing in song:
if sing == 'look' and skipcount <= 0:
print (sing)
skipcount = 3
elif skipcount > 0: skipcount = skipcount - 1
continue
elif skipcount == 0:
print ('a' + sing)
skipcount = skipcount - 1
else:
print (sing)

output:

always
look
aside
of
life

#My Ques: How does it count to 3 or 0 in order to print look and aside? from which direction?

defendersart
Автор

Wow, this is so handy and helpful with the operand statement!!
Learn for a while but figure out now!!

bradyhuang
Автор

plenty example very simple and plain english ! weldone mate keep it up and upload more.

truthseeker
Автор

i can't figure this out when variables are text, the compiler is not understanding the if statement at all.

sqlicto
Автор

Thanks, man. I'm hear for the same reason that "no" stated.

spearius
Автор

can anyone please help me whats wrong in this code:

first = input("Enter the first no.")
if first == type(str):
print("Enter a valid no.")

after putting string or integer the program gets ended

vace
Автор

Hi @sentdex I have an issue and I'd love if you could help me. I have a variable called name and two variables called is_male and is_female. The If statement works perfectly (if is_male and not (is_female):) and basically asks you for an input which is a name you want to name the program like. So I want to make the program print something else if the user types a name (This name being Connor, sort of an Easter egg). How could I do this? Also, if you're interested, I can send you a screenshot if you give me your discord or something like that, thank you!

victorvictus
Автор

I was not understanding this as my teacher taught me thank you so

suchanakamil
Автор

Hi sentdex, i still have a question:
What if i wanted to put more than 1 statements into a single one like this: "if z == 10, x == 9:"
Because i tried this and it didnt work (the problem is with the comma i believe)
So what should i do?

Thanks in advance

EvdeKsp
join shbcf.ru