Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet15/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   11   12   13   14   15   16   17   18   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Indentation and Lines
There  is  nothing  like  braces  to  indicate  a  block  of  code  for  function  and
class  in  Python.  Normally,  a  block  of  code  is  represented  by  a  line
indentation that gets enforced in a strong manner. Importantly, the spaces in
the indentation vary; however, every statement in the block must have the
same amount of indentation. For instance,
if False:
print "False"
else:
print "True"
However, the block of the statement below will generate an error


if False:
print "Result"
print "False"
else:
print "Result"
print "True"
Consequently,  all  continuous  lines  you  indent  using  the  same  number  of
spaces  will  for  a  block.  Let  us  use  another  example  to  show  various
statement blocks. I will advise you not to try to understand the logic of the
program.  However,  your  aim  is  to  understand  the  various  blocks
irrespective of their structure.
import sys
try:
# open file stream
file = open(fileName, "w")
except IOError:
print "Error when writing to", fileName
sys.exit()
print "Enter '", fileFinish,
print "' When finished"
while fileText != fileFinish:
fileText = real_input("Enter text you want: ")
if fileText == fileFinish:
# close the file
file.close


break
file.write(file_text)
file.write("\n")
file.close()
fileText = real_input("Enter filename: ")
if len(fileName) == 0:
print "Next time input something"
sys.exit()
try:
file = open(fileName, "r")
except IOError:
print "Error reading file requested"
sys.exit()
fileText = file.read()
file.close()
print fileText

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   11   12   13   14   15   16   17   18   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish