Boolean Type and Expressions in Python
Concept of Boolean type expressions in Python, understanding how they can only have True or False values. Learn about generating boolean results through comparisons of numerical values or strings, and see examples of doing numerical and string comparisons in Python.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Clarifications on Strings I received a number of queries Here are some explanations. For more details, please surf the Internet. 1
Whats the difference? char string1[6] = "apple"; char *string2 = "apple"; The characters inside the array can be changed. string1 a p p l e \0 The value inside this box, which is the address of the location that contains a , cannot be changed. For ease of reference, we shall call string1 a constant pointer/address. string2 a p p l e \0 string2 is a pointer whose value can be changed. That is, it can point to a different location. However, this string literal is residing in read-only memory, so its contents cannot be changed. 2
Example #1 char word1[5] = "good"; char word2[4] = "bye"; word1 \0 g o o d word1 = word2; word2 \0 b y e Attempt to change the value of constant pointer word1! Not allowed! strcpy(word1, word2); word1 o y e \0 \0 d \0 g b o word1 is not changed. Characters in array word1 are changed. Allowed! word2 \0 b y e 3
Example #2 (Week 10 Discussion Q5) char *fruit1 = "apple"; char *str1 = "yes"; fruit1 \0 a p p l e fruit1 = str1; str1 \0 b y e fruit1 now points to bye . Allowed! char *fruit2 = "apple"; char *str2 = "yes"; strcpy(fruit2, str2); fruit2 \0 a p p l e Pink boxes apple are in read- only memory; cannot overwrite them with bye . Not allowed! str2 \0 b y e 4