skip to main | skip to sidebar

Python Programs and Examples

Pages

  • Home
 
  • RSS
  • Facebook
  • Twitter
Wednesday, October 24, 2012

Control Structures in Python

Posted by Raju Gupta at 5:00 AM – 7 comments
 
This Program explains different control structures in python

If
====
# basic "If"
if boolean:
    x = 1
else:
    x = 0

# Not so basic "If"
# Notice the new keywords!
if (boolean and otherboolean) or ( not boolean ):  #oops, this is just if(boolean), oh well...  :~)
    x = 1
elif not otherboolean:
    x = 0
else:
    x = 100000000000000000000 # Big numbers make if statements less boring!

While
=====

# This is it...  
while i < 100:
    i + 1

# More generally:
while condition == true:
    """do the following"""
    ...
    ...
    condition = false.

# Infinite Loop:
while 1:
    print "I'm loopy!"


FOR
====

# Basic For Loop
for item in list:
    dosomething(item)

# The traditional C for loop has a different form in Python:
for x in range(0, 100):
    dosomething(x)

# More interesting example:
def buglove( UIUC ):
    for bug in UIUC:
        if type( bug ) == type( chinese_lady_beetle() ):
            crush( bug )
        else:
            hug( bug )






Labels: Control Structure Email This BlogThis! Share to X Share to Facebook

7 Responses so far.

  1. rose says:
    December 28, 2017 at 10:07 PM

    It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    python training in bangalore|

  2. Keerthana says:
    May 14, 2020 at 10:13 AM

    The Concepts of Python Explanation Processes Flow Is Excellent...Thanks For Sharing with us
    python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

  3. surya says:
    July 17, 2020 at 7:39 AM

    Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.
    Angular JS Training in Chennai | Certification | Online Training Course | Angular JS Training in Bangalore | Certification | Online Training Course | Angular JS Training in Hyderabad | Certification | Online Training Course | Angular JS Training in Coimbatore | Certification | Online Training Course | Angular JS Training | Certification | Angular JS Online Training Course

  4. praveen says:
    August 17, 2020 at 5:34 AM

    First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics,
    i will be always checking your blog thanks
    web designing training in chennai

    web designing training in porur

    digital marketing training in chennai

    digital marketing training in porur

    rpa training in chennai

    rpa training in porur

    tally training in chennai

    tally training in porur

  5. deiva says:
    August 18, 2020 at 8:07 AM

    Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article...
    java training in chennai

    java training in omr

    aws training in chennai

    aws training in omr

    python training in chennai

    python training in omr

    selenium training in chennai

    selenium training in omr

  6. Anonymous says:
    July 15, 2021 at 6:34 PM

    no deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - takipcialdim.com/tiktok-takipci-satin-al/ - instagram beğeni satın al - instagram beğeni satın al - google haritalara yer ekleme - btcturk - tiktok izlenme satın al - sms onay - youtube izlenme satın al - google haritalara yer ekleme - no deposit bonus forex 2021 - tiktok jeton hilesi - tiktok beğeni satın al - binance - takipçi satın al - uc satın al - finanspedia.com - sms onay - sms onay - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - perde modelleri - instagram takipçi satın al - instagram takipçi satın al - cami avizesi - marsbahis

  7. Digital Wheels India says:
    February 17, 2022 at 12:37 AM

    Really appreciate the author for such kinds of article with us. It was really awesome and very helpful for all of us. Please keep sharing. Read more about python training institutes in delhi

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments (Atom)
  • Popular
  • Recent
  • Archives

Popular Posts

  • To Send the entire contents of directory as an email Message.
    Here is a Python Program to send the entire contents of a directory as an email message #!/usr/bin/env python """Send the...
  • Control Structures in Python
    This Program explains different control structures in python If ==== # basic "If" if boolean: x = 1 else: x = 0 # No...
  • Python Code for creating Screen saver
    This is the Python code for creating a screensaver of a moving ball. The ball will bee moving along the screen and when it hits any of the ...
  • Python script for walking the directory tree structure but excluding some directories and files
    The script walks the directory structure recursively. Some of the directories and files can be excluded from the walk by providing them in ...
  • XML to CSV Converter
    Python Program to extract each execution data (few children in xml) and create a csv file. def xml2csv(inputFile,outputFile,elemName,n...
  • HTML Email using Python
    We created a module called sendmail which email html content. Each of application dumps data from the datastructure into html format and th...
  • Overview of Python Programming Language
    Python is an easy to learn, powerful programming language. It has efficient high level data structures and a simple but effective approac...
  • Fast and efficient Backup script that works on Windows and Linux
    This python script backup your directory structure that works on Linux and Windows both. It directly uses the shell to do this task and she...
  • Run Application from host
    import os os.execl( "c:/Windows/Notepad.exe", "c:/userlog.txt") print "Running notepad" #or import subpro...
  • Orphan Checker
    The script does not use any outside libraries, thus keeping its execution simple. we will start by initializing the arrays that we'll...
Powered by Blogger.

Archives

  • ▼  2012 (66)
    • ▼  October (28)
      • Find text/pattern under parent folder from matched...
      • XML to CSV Converter
      • XSL to CSV converter
      • Spell Corrector in Python
      • Format a plain ASCII file using Python script
      • Control Structures in Python
      • Python script to zip and unzip files
      • Fast and efficient Backup script that works on Win...
      • File Splitter Script
      • Python script for walking the directory tree struc...
      • Python XML Parser
      • IP Address Generation
      • Orphan Checker
      • HTML Email using Python
      • Python interface to load commands.
      • Python script to Validate Tabular format Data and ...
      • Python script to Load Configuration file content i...
      • Python Script to search file for specific content
      • Network Wise File Concatenation
      • Python Script for Adding or Subtracting the Dates
      • Program to create make file in VMS/UNIX
      • Python Code for creating Screen saver
      • Run Application from host
      • Multithreading in Python
      • This utility determines the size of a folder and i...
      • Using UNIX Environment Variables From Python
      • CVS Macro for Commited Files
      • Generating unique id's
    • ►  September (36)
    • ►  March (1)
    • ►  February (1)
 

Labels

  • Command Execution Using Python (2)
  • Control Structure (1)
  • CSV Examples (4)
  • Database (3)
  • Features of Python Programming Language (1)
  • File Example (2)
  • IF Statement (1)
  • List (2)
  • Mail (5)
  • Multithreading (1)
  • MySQL (3)
  • Python Date Example (2)
  • Python Example (2)
  • Python File Example (7)
  • Python Introduction (1)
  • Python Network Example (1)
  • Python XML Parser (2)
  • Searching Example (2)
  • Simple Calculation Program (1)
  • Strings (4)
  • Zip File Example (1)

Followers

 
 
© 2011 Python Programs and Examples | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger