473,549 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is "if not" in python?

1 New Member
For example what does the third line mean?

Expand|Select|Wrap|Line Numbers
  1. contents = open("file.dat").read()
  2. for line in contents.split("*"):
  3.   if not line: continue  # Remove initial empty string.
  4.   line = line.strip()   # Remove whitespace from beginning/end of lines.
  5.   items = line.split("-")
  6.   print items[0], ":", " ".join(items[1:])
  7.  
Mar 19 '12 #1
4 62163
Smygis
126 New Member
it means that if line does not contain anything it continues to the next iteration of the loop
Mar 19 '12 #2
eGrove Systems
6 New Member
'If not' is a condition which is used to check whether the list is empty or not
for example:
Expand|Select|Wrap|Line Numbers
  1.          lister=[]
  2.          if not lister:
  3.                 print "list is in empty"
Dec 14 '12 #3
maya29988
7 New Member
if not <condition> in python is equal to if (!<condition>) in c.
May 2 '14 #4
Hellstorm6X
1 New Member
It's really an easy concept.
May 2 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11105
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want to insert into a table but only if the table exists. How does one, in general, from PHP, test for the existence of a table, without getting an...
10
1858
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None" vs. "!= None" ...} This seemed like a good idea at the time :(). Twice, recently, however, as my app grew, I thought, hmm... it would make...
5
2063
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this, it comes to me this way. <?xml version="1.0" encoding="iso-8859-1" ?>
12
3205
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
12
20628
by: John | last post by:
I can't get my head around this! I have the following code: <% .... Code for connection to the database ... .... Code for retrieving recordset ... If Not rs.EOF Then ... Do something...
18
3618
by: desktop | last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is identified by a unique ID which gets returned by the function getId(). All bobs are descendants from class BaseBob which is an abstract class that has the virtual function getId(). I then have a function that prints a special string when a bob meets another bob (all...
4
2363
by: kang jia | last post by:
hi currently i am getting an array from database,the code is in the following, if id do not exist variable b will render an empty array. at this time, i would like to check if this array is empty means the id is not exist in my Booking1 table. How should i express this " if empty " concept in python? def confirmUp(request):...
3
20895
by: kang jia | last post by:
hi, currently i am doing booking car online and one of the function is cancel and update booking. if the booking number users entered in is not exist. it will redirect the page stating that the booking number did not exist or you never book with us. however. i would like to express this "if Not exist" concept in my coding. how should i achieve...
7
59237
by: itsraghz | last post by:
Hello All, I remember in MySQL we do have "IF EXISTS", 'IF NOT EXISTS" clause/keyword in the DDL statements (CREATE,DROP etc.,) to avoid unnecessary bombing. Do we have such facility in Oracle? If not is there any other easy way to achieve it? I am using Oracle 10g. I have been searching through google and also in oracle.com but unable to...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.