python session day-t payilagam for loop and if condition
for loop:
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
Syntax:
for variable in Sequence
example:
txt = '1234' for num in txt: print(num,end=' ') output: 1 2 3 4
If condition:
The If statement works by checking the expression to see whether a condition is met and returns a value based on the output obtained.
syntax: if condition: if condition is True else: if condition is False
example
x=20 if x>=20: print(x is within 20) else : print(x is above the limit) output: x is within 20
txt = '12a4' for num in txt: if num>='0' and num<='9': print(num,end=' ') else: print('Not Decimal',end=' ') Output: 1 2 Not Decimal 4 above code is the example of combines if and for.
name = input("Your Name please: ")
print(name)
for alphabet in name:
print(alphabet, end='*')
output:
R*A*J*A
The code checks each and every index and prints the output.
name1 = input("Enter the first name: ") name2 = input("Enter the second name: ") name3 = input("Enter the third name: ") name4 = input("Enter the fourth name: ") name = [name1, name2, name3, name4] for letter in name: if letter[0]=='G': print(letter) else: continue for alphabet in name: if alphabet[-1]=='a': print(alphabet) else: continue for alpha in name: for i in alpha: if i==' ': print(alpha) else: continue for character in name: if len(character)>9: print(character) else: continue output: Enter the first name: Guhanraja Enter the second name: Lakshmi Pritha Enter the third name: Guru Prasanna Enter the fourth name: Varatharajan Guhanraja Guru Prasanna Guhanraja Lakshmi Pritha Guru Prasanna Lakshmi Pritha Guru Prasanna Lakshmi Pritha Guru Prasanna Varatharajan
The above is the detailed content of python session day-t payilagam for loop and if condition. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
