• Register
0 votes
24 views

I am a newbee. I was doing my coding practice. I was trying to check if a variable exist in a file or not. I wrote some code to do this :

def Check():
  if Check.my_variable is None:
     Check.my_variable = >>>
  Check.my_variable = None

 but it gives me error :

 File "main.py", line 3
    Check.my_variable = >>>
                        ^
SyntaxError: invalid syntax

What is the error in my code and why am I getting this type of error. 

10 7 2
6,050 points

1 Answer

0 votes

You are getting this error becuse of your conditon for your program should be True, False Or None or you have an empty srting list.

You should write your code like:

def Check():
  if Check.my_variable is None:
     Check.my_variable = ...
  Check.my_variable = None

Please use this code and let me know if this is working properly for you or not. I am sure that you can get the exact result using this code. 

11 6 4
34,930 points

Related questions

1 vote
1 answer 26 views
26 views
Problem: I am starting writing code in python. I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote the following code: if 'key1' in dict.keys(): print "Present" else: print "Thanks" If there any other way to check this, please let me know.
asked Mar 10 Gavin 15.3k points
1 vote
1 answer 26 views
26 views
Problem: I was trying to check if an element does exist in a list using a pyhton program: primary_list = [ 10, 12, 16, 6, 20, 33 ] a = input("Please enter a number to check if this exists in the list: ") print("Checking if input exists in this list : ") for ... not giving any output that is right. What should I do to fix this and how to check if an element does exist in a list. Thanks in advance.
asked May 16 samhaz 5k points
1 vote
1 answer 20 views
20 views
Problem: I tried to check if a string is a palindrome or not so I wrote this program in python: def Word(str): for i in range(0, len(str)/2): if str[i] != str[len(str)-i-1]: return False return True a = input("Enter a word to check:") ... TypeError: 'float' object cannot be interpreted as an integer What should I do now and how to check if a string is a palindrome or not using python program?
asked May 15 samhaz 5k points
1 vote
1 answer 28 views
28 views
Problem: I wrote a code to check if a number is even or odd in python. The program is in the snippet below: number = input("Please enter any number to check if it is even or odd: ") result = number % 2 if result == 0: print("The number ... 2 TypeError: not all arguments converted during string formatting Why this error message is appearing & what is the problem with my program? Thanks in advance.
asked May 13 samhaz 5k points
3 votes
1 answer 12 views
12 views
Problem: Hi all, I am trying to figure out the dictionary related problems in python. Dictionary is really fun to learn and work with. Let’s say, I have a dictionary dict = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'} If ... needed to check every value inside the dictionary what can I do for that? So, I want to know how to check if a value is in a dictionary python?
asked Mar 24 Gavin 15.3k points