Тёмный

For Loops With Strings 

MIT OpenCourseWare
Подписаться 5 млн
Просмотров 62 тыс.
50% 1

MIT 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016
View the complete course: ocw.mit.edu/6-0001F16
Instructor: Dr. Ana Bell
This in-class question demonstrates how loops can be used with strings in Python.
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu

Опубликовано:

 

14 фев 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 17   
@abdelkarimjaja7740
@abdelkarimjaja7740 5 лет назад
great lecture, thanks, MIT
@akbarrauf2741
@akbarrauf2741 7 лет назад
thank you ,mit
@Zoronoa01
@Zoronoa01 5 лет назад
00:23
@gpjapan
@gpjapan 7 лет назад
Thank you for your lecture. I was confused by this code. I think it is because I am confused about char1 and char2. char2 does not refer to the 2nd character in s2. Is char undefined? Python knows what char refers to? Thanks again for your lecture. It is very helpful.
@phillipgonzalez9776
@phillipgonzalez9776 5 лет назад
"char1" and "char2" are just the names of temporary variables that will represent each character in the strings s1 and s2, respectively, because of the for loops.
@phillipgonzalez9776
@phillipgonzalez9776 5 лет назад
Another thing that could be potentially confusing is that the print statement says "common letter" but the code actually is comparing every character, including the " " characters, hence "common letter" being printed 7 times for the matches "m", "i", "t", " ", "u", " ", "r"
@kikykeeyansyah4021
@kikykeeyansyah4021 5 лет назад
Are the spaces include?
@funnyh0rr0r31
@funnyh0rr0r31 5 лет назад
Where are included? In string every symbol considered an element and it's part of string. For example string "nice day" will have 8 symbols. " nice day " - 10 symbols.
@shokobata
@shokobata 4 года назад
@@funnyh0rr0r31 If you mean if the loop checks if the spaces are equal then yes
@thewryreport
@thewryreport 3 года назад
@@shokobata Then why is the answer not 10? m = 1, i = 2, t = 1, space = 2, u = 1, space = 2, r = 1
@thewryreport
@thewryreport 3 года назад
OK I think I get it now, it's because of the break, it only counts the 1st instance of each letter, so it's just m + i + t + space + u + space + r once each
@hieunguyenminh4677
@hieunguyenminh4677 7 месяцев назад
@@thewryreport thanks, i also think the answer is 10 before
@dg2q
@dg2q Год назад
do we count the 2 spaces?
@alcikelly2496
@alcikelly2496 10 месяцев назад
Yes, you're absolutely right! It prints "common letter" for "m", "i", "t", " ", "u", " ", and "r", which is quite misleading, because it is checking every CHARACTER in the string, not just letters.
@dg2q
@dg2q 9 месяцев назад
@@alcikelly2496 gotcha thanks
@jfritz6233
@jfritz6233 4 года назад
The for loop really should have an else: statement in case the result is false.
Далее
4. Decomposition, Abstraction, and Functions
41:09
Просмотров 227 тыс.
7. Testing, Debugging, Exceptions, and Assertions
41:33
КАК СПРЯТАТЬ КОНФЕТЫ
00:59
Просмотров 774 тыс.
Выходи искать ЛТС-85
00:55
Просмотров 59 тыс.
For Loops - Beau teaches JavaScript
6:37
Просмотров 93 тыс.
Functions as Arguments
3:33
Просмотров 54 тыс.
Python For Loops - Programming for Beginners
5:19
Просмотров 130 тыс.
5. Tuples, Lists, Aliasing, Mutability, and Cloning
41:28
1. What is Computation?
43:06
Просмотров 1,8 млн
While loops in Python are easy ♾️
6:58
Просмотров 298 тыс.
8. Object Oriented Programming
41:44
Просмотров 605 тыс.