String comparison in Python; examples + exercises
#python #stringspython #asciicode #stringcomparison
Exercises:
Compare the following strings in two ways - with the len() function and without using the len() function:
1.
x = 'triceratops'
y = 'spinosaurus'
2.
x = 'relativism'
y = 'availability'
3.
hd1 = 'All the king's horses and all the king's men couldn't put Humpty together again!'
hd2 = 'All the king's horses and all the king's men couldn't put humpty together again!'
______________________________________________________________________________________
Summary of the video
First example:
x = 'cupboard'
y = 'lamp'
First of all compared these strings using the len() function and if sentence. But after that we compared them without using the len() function and got an opposite result. In order to explain it we need to know what is ASCII code.
Let's take a look at ASCII conversion table.
Second example:
m = 'chair'
n = 'table'
Although these two strings contain the same of characters, in the comparison without len() the string 'table' is greater than 'chair', because the ASCII code of the letter t is greater than the ASCII code from the letter c.
ASCII codes from uppercase letters are less than ASCII codes from lowercase letters.
How Python compares strings without the len() function?
It compares ASCII codes from each character going character for character. If the codes from the first character of each strings are different Python immediately gives the result of comparison and doesn't move to the next character.
Third example:
m = 'chair'
n = 'Table'
Fourth example:
m = 'chair'
z = 'cHair'
Fifth example:
g1 = 'How are you friend?'
g2 = 'How are you Friend?'
Python course #2 in English 11
Python programming language course in English
#pythonexercises #pythontasks #python程式設計語言 #python程式設 #程式設計語言 #程式設
Видео String comparison in Python; examples + exercises канала Olga Soboleva
Exercises:
Compare the following strings in two ways - with the len() function and without using the len() function:
1.
x = 'triceratops'
y = 'spinosaurus'
2.
x = 'relativism'
y = 'availability'
3.
hd1 = 'All the king's horses and all the king's men couldn't put Humpty together again!'
hd2 = 'All the king's horses and all the king's men couldn't put humpty together again!'
______________________________________________________________________________________
Summary of the video
First example:
x = 'cupboard'
y = 'lamp'
First of all compared these strings using the len() function and if sentence. But after that we compared them without using the len() function and got an opposite result. In order to explain it we need to know what is ASCII code.
Let's take a look at ASCII conversion table.
Second example:
m = 'chair'
n = 'table'
Although these two strings contain the same of characters, in the comparison without len() the string 'table' is greater than 'chair', because the ASCII code of the letter t is greater than the ASCII code from the letter c.
ASCII codes from uppercase letters are less than ASCII codes from lowercase letters.
How Python compares strings without the len() function?
It compares ASCII codes from each character going character for character. If the codes from the first character of each strings are different Python immediately gives the result of comparison and doesn't move to the next character.
Third example:
m = 'chair'
n = 'Table'
Fourth example:
m = 'chair'
z = 'cHair'
Fifth example:
g1 = 'How are you friend?'
g2 = 'How are you Friend?'
Python course #2 in English 11
Python programming language course in English
#pythonexercises #pythontasks #python程式設計語言 #python程式設 #程式設計語言 #程式設
Видео String comparison in Python; examples + exercises канала Olga Soboleva
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Looping through strings in Python; examples + exercises](https://i.ytimg.com/vi/HXM-IjMmvU0/default.jpg)
![Ejercicios de strings in Python con soluciones](https://i.ytimg.com/vi/PAiPR3e1emA/default.jpg)
![Java Tutorial for Beginners - Made Easy - Step by Step](https://i.ytimg.com/vi/3u1fu6f8Hto/default.jpg)
![Сравнение строк в Python; примеры и упражнения](https://i.ytimg.com/vi/hw6W9Cfl9Sw/default.jpg)
![String theory - Brian Greene](https://i.ytimg.com/vi/kF4ju6j6aLE/default.jpg)
![Python Object Oriented Programming (OOP) - For Beginners](https://i.ytimg.com/vi/JeznW_7DlB0/default.jpg)
![Строки в Python: упражнения и ответы](https://i.ytimg.com/vi/ZkvL0baiEaM/default.jpg)
![Comparación de strings en Python; ejemplos + ejercicios](https://i.ytimg.com/vi/hsaHP2GGJzU/default.jpg)
![Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008](https://i.ytimg.com/vi/k6U-i4gXkLM/default.jpg)
![Aufgaben zu Strings in Python: Übungen und Lösungen](https://i.ytimg.com/vi/9_0fqpYska8/default.jpg)
![REST API concepts and examples](https://i.ytimg.com/vi/7YcW25PHnAA/default.jpg)
![LIVE: Let's build advanced save & load systems - Unity3D](https://i.ytimg.com/vi/4h2CvULKqic/default.jpg)
![Best of Fluent 2012: /Reg(exp){2}lained/: Demystifying Regular Expressions](https://i.ytimg.com/vi/EkluES9Rvak/default.jpg)
![The Science of How the Body Heals Itself with William Li, M.D.](https://i.ytimg.com/vi/wlJEGJvI1UA/default.jpg)
![Python Count Occurrences of Letters, Words and Numbers in Strings and Lists](https://i.ytimg.com/vi/szIFFw_Xl_M/default.jpg)
![Java vs Python Comparison | Which One You Should Learn? | Edureka](https://i.ytimg.com/vi/s3Ejdx6cIho/default.jpg)
![Google Python Class Day 1 Part 1](https://i.ytimg.com/vi/tKTZoB2Vjuk/default.jpg)
![String Permutation Algorithm](https://i.ytimg.com/vi/nYFd7VHKyWQ/default.jpg)
![Python Pattern Programs - Printing Stars '*' in Right Angle Triangle Shape | Star Pattern](https://i.ytimg.com/vi/rUy_Nq9DHTs/default.jpg)
![How to String & Sucker Tomato Plants](https://i.ytimg.com/vi/qJgA4n-sCE8/default.jpg)