0

I started the Python guides

(https://www.techbeamers.com/python-keywords-identifiers-variables/#keywords-in-python)

and under the title "Testing If An Identifier Is Valid.", it doesn't work for me for some reason.

PFB the snapshot of what I am trying:

keyword.iskeyword() screenshot


The error I am getting: Basically, I do not get any return, not True or False.

When I put those lines for example:

import keyword
keyword.iskeyword("techbeamers")

I receive

"Process finished with exit code 0"

What am I supposed to do to make it work?

P.S I am new to this forum and coding in general, if I made mistake in the post/ haven't added enough information please let me know.

Thank you!

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51
Aviv
  • 129
  • 1
  • 11
  • It works fine for me. Can you describe a bit more what you are actually doing on your computer when this occur ? How are you staring python ? Are you running python interactively, or are you creating a file and running that file as a python program ?And which operating system, and python version are you using.? – nos Oct 06 '18 at 19:26
  • 2
    If you want to see the value, you have to `print` it. Expression values only get auto-printed in interactive mode. – user2357112 Oct 06 '18 at 19:28
  • See [Why not upload images of code when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question) on [meta]. We ask that you include code *as text*, so it can be copied-and-pasted, and use images only to illustrate problems that can't be shown any other way (showing how a GUI display is rendered compared to how it should, for example). – Charles Duffy Oct 06 '18 at 19:33

1 Answers1

2

This code is intended to be run from the interactive Python REPL:

me@host $ python
Python 2.7.14+ (default, Mar 13 2018, 15:23:44)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.iskeyword('if')
True

It shows "True" because this is a Read-Eval-Print-Loop.

You appear to have put it into a file and run it as a program. This will indeed not produce any output:

me@host $ cat test.py
import keyword
keyword.iskeyword('if')

me@host $ python test.py
(no output)

In this case you have to add your own print statement:

me@host $ cat test.py
import keyword
print(keyword.iskeyword('if'))

me@host $ python test.py
True
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Hey, I am really new at this and tries to understand it but failed miserably. I will sort my questions by numbers: 1. Python REPL - PyChram is example of REPL? 2. I am not sure what that part stands for: me@host $ python Python 2.7.14+ (default, Mar 13 2018, 15:23:44) [GCC 7.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. 3. I think I get it. I didn't get any output since I haven't put a command to Print it, correct? Thank you. – Aviv Oct 06 '18 at 19:44
  • 1. "REPL" is a mode in which you interactively type Python commands to be executed immediately, showing you the output (for testing and debugging purposes). See [this question](https://stackoverflow.com/questions/19709105/does-pycharm-have-interactive-python-interpreter) for how to get an interactive Python prompt in PyCharm. 2. That is a "screenshot" of a system terminal where I ran `python` to get a REPL (outside of PyCharm) and entered the commands you're looking at. 3. Right. – that other guy Oct 06 '18 at 19:48