Python je programski jezik, ki razlikuje velike in male črke, kar pomeni, da jezik različno obravnava velike in male črke. Na primer, v Pythonu spremenljivka 'x' ni enaka spremenljivki 'X'. To vedenje se razlikuje od nekaterih drugih programskih jezikov, kot je JavaScript, ki ne razlikujejo med velikimi in malimi črkami.
V Pythonu imena spremenljivk, imena funkcij in ključne besede razlikujejo med velikimi in malimi črkami. To pomeni, da če definirate spremenljivko 'x' in jo pozneje poskušate sklicevati kot 'X', jo bo Python obravnaval kot drugo spremenljivko in dobili boste napako. Podobno, če poskusite poklicati funkcijo 'print' namesto 'Print', vam bo Python prav tako dal napako.
Tukaj je primer, kako občutljivost na velike in male črke vpliva na imena spremenljivk v Pythonu:
x = 5 X = 10 print(x) # Output: 5 print(X) # Output: 10
Izhod
Pojasnilo:
V tem primeru smo definirali dve spremenljivki, 'x' in 'X,' z različnimi vrednostmi. Ko jih natisnemo, vidimo, da jih Python obravnava kot ločene spremenljivke in jim dodeli različne vrednosti.
Občutljivost na velike in male črke velja tudi za imena funkcij v Pythonu. Na primer:
print('Hello, World!') # Output: Hello, World! Print('Hello, World!') # Output: NameError: name 'Print' is not defined
Izhod
Pojasnilo:
vgrajena funkcija 'print()' se razlikuje od funkcije 'Print()'. Prva bo delovala po pričakovanjih, druga pa bo dala napako, ker ni definirana funkcija.
Ključne besede v Pythonu prav tako razlikujejo med velikimi in malimi črkami. To pomeni, da če uporabite ključno besedo, kot je 'če' ali 'za' z malimi črkami, bo delovala po pričakovanjih. Če pa ga uporabite z velikimi črkami, ga bo Python obravnaval kot ime spremenljivke in dobili boste napako.
Izvorna koda:
if x <10: print('x is less than 10') if x < 10: # output: nameerror: name 'if' not defined pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/python-tutorial/48/is-python-case-sensitive-3.webp" alt="Is Python Case Sensitive"> <p> <strong>Explanation:</strong> </p> <p>In the above code, we have created two if statements. In the first if statement, we have used the proper syntax as Python is case-sensitive. We have created the first if statement with small i, and the second if statement has a capital I which means it is not correct syntax, so it will throw an error.</p> <p>In addition to variable names, function names, and keywords, Python is also case-sensitive when it comes to file names. This means that the file 'example.txt' is different from the file 'Example.txt,' and the interpreter will treat them as separate files.</p> <p>It is important to keep in mind that Python is case-sensitive when naming variables, functions, and keywords. This can lead to errors and unexpected behavior if you're not careful. To avoid these issues, it is a good practice to use a consistent naming convention, such as using lowercase letters for all variable and function names.</p> <p>In conclusion, Python is a case-sensitive programming language. This means that the language treats uppercase and lowercase characters differently. This applies to variable names, function names, keywords, and file names. It's important to keep in mind that case sensitivity can lead to errors and unexpected behavior if you're not careful, so it's a good practice to use a consistent naming convention.</p> <hr></10:>