When running the code, a syntax error occurs – inconsistent use of tabs and spaces in indentation. What does this mean and how to solve this problem? The fact is that python enforces uniformity in the use of spaces, which show the indentation of parts of the code. If you use tab, it can get tricky because some of the tabs can be misinterpreted as spaces. As a result, you see a syntax error that can be difficult to fix. Читать
Архив метки: Python
Python: Basic Text Input and Output Operators
The very first text operations and basic information about Python that helps you start programming right away:
# Comments
Delimiters ” or “” and escaping characters ’ and ”
print(‘Hello world’) – newline
end=’…’ – next print will be glued
escape sequences:
a – system speaker
n – newline (empty line)
t – tab type indent
+ string concatenation without delimiter
* repeat lines without delimiter
continuation of a line of code on the next line
input(‘Press Enter to exit’)
Basic mathematical operators (+,-,*,/,//,%).
Compound assignment statements
String methods (applied to a string with text): I am cat
.upper() I Am CAT
.lower() i am cat
.title() I Am Cat
.replace(old,new,max number of replacements) replaces the old text with the new one
.swapcase() reverse case i Am Cat
.capitalize() the first letter is capital, the rest are lowercase I am cat
.strip() string without intervals Iamcat
Python: базовые операторы ввода и вывода текста
Самые первые операции с текстом и базовые сведения о Python, которые помогают тут же начать программировать:
# Comments- Ограничители
''или""и экранирование символов'и" - p
rint('Hello world')– переход на новую строку end='...'– следующий print склеитсяescape-последовательности:
a– системный динамик
n– переход на новую строку (пустая строка)
t– отступ типа tab+сцепление строк без разделителя*повторение строк без разделителяпродолжение строки кода на следующей строкеinput('Press Entr to exit')- Базовые математические операторы (
+,-,*,/,//,%). - Составные операторы присвоения
- Строковые методы (применяются к строке с текстом): I am cat
.upper()I Am CAT
.lower()i am cat
.title()I Am Cat
.replace(old,new,max число замен)заменяет старый текст на новый
.swapcase()меняет регистры наоборот i Am Cat
.capitalize()первая буква большая, остальные строчные I am cat
.strip()строка без интервалов Iamcat
Python – Boolean Operators and Conditions
Basic conditions in Python:
< (one less than the other)
> (one more than the other)
<= (one is less than or equal to the other)
>= (one is greater than or equal to the other)
!= (one is not equal to the other)
== (one is equal to the other)
Examples of using conditions:
print(5 > 4)
True #result
print(‘cat’==’dog’)
False #result
Программирование: считать с нуля или с единицы…
За основу берем цифру, равную трём
(С трёх удобней всего начинать),
Приплюсуем сперва восемьсот сорок два
И умножим на семьдесят пять.
Льюис Кэрролл «Охота на Снарка»,
Почему программисты считаю с нуля:
Это система, которая пришла из языка C, который долгое время оставался самым популярным языком и стал предком многих ЯП (языков программирования).
Также на западе принято считать с нуля многие вещи, например, этажи в зданиях. Читать
Ошибка Python: inconsistent use of tabs and spaces in indentation
При запуске кода возникает ошибка синтаксиса— inconsistent use of tabs and spaces in indentation. Что это означает и как решить эту проблему? Дело в том, что python следит за соблюдением единообразия в использовании пробелов, которые показывают отступы частей кода. Если вы используете tab, то могут возникнуть сложности, так как часть табов может неверно интерпретироваться в пробелы. В итоге, вы видите ошибку синтаксиса, которую бывает трудно исправить. Читать