Python NameError: имя `xrange` не определено Решение

–í Python 3 —Ñ—É–Ω–∫—Ü–∏—è xrange –±—ã–ª–∞ —É–¥–∞–ª–µ–Ω–∞. –ï—Å–ª–∏ –≤—ã –ø–æ–ø—ã—Ç–∞–µ—Ç–µ—Å—å –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å —Ñ—É–Ω–∫—Ü–∏—é xrange –≤ –ø—Ä–æ–≥—Ä–∞–º–º–µ Python 3, –≤—ã —Å—Ç–æ–ª–∫–Ω–µ—Ç–µ—Å—å —Å –æ—à–∏–±–∫–æ–π NameError: name " xrange " –Ω–µ –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–∞ –æ—à–∏–±–∫–∞.

–í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –º—ã —Å–æ–±–∏—Ä–∞–µ–º—Å—è –æ–±—Å—É–¥–∏—Ç—å, —á—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç —ç—Ç–∞ –æ—à–∏–±–∫–∞ –∏ –ø–æ—á–µ–º—É –≤—ã –º–æ–∂–µ—Ç–µ —Å –Ω–µ–π —Å—Ç–æ–ª–∫–Ω—É—Ç—å—Å—è. –ú—ã –æ–±—Å—É–¥–∏–º –ø—Ä–∏–º–µ—Ä —ç—Ç–æ–π –æ—à–∏–±–∫–∏, —á—Ç–æ–±—ã –≤—ã –º–æ–≥–ª–∏ —É–∑–Ω–∞—Ç—å, –∫–∞–∫ –∏—Å–ø—Ä–∞–≤–∏—Ç—å –µ–µ –≤ —Å–≤–æ–µ–º –∫–æ–¥–µ.

NameError: name " xrange " –Ω–µ –æ–ø—Ä–µ–¥–µ–ª–µ–Ω

–í Python 2 —Ñ—É–Ω–∫—Ü–∏—è xrange –ø–æ–∑–≤–æ–ª—è–µ—Ç —Å–æ–∑–¥–∞–≤–∞—Ç—å –¥–∏–∞–ø–∞–∑–æ–Ω —á–∏—Å–µ–ª. –†–∞—Å—Å–º–æ—Ç—Ä–∏–º —Å–ª–µ–¥—É—é—â–∏–π —Ñ—Ä–∞–≥–º–µ–Ω—Ç –∫–æ–¥–∞:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç [0, 1, 2], —Ç–æ –µ—Å—Ç—å –≤—Å–µ —á–∏—Å–ª–∞ –≤ –¥–∏–∞–ø–∞–∑–æ–Ω–µ –æ—Ç 0 –¥–æ 3 (–∫—Ä–æ–º–µ 3). –§—É–Ω–∫—Ü–∏—è xrange () –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç —Å–ø–∏—Å–æ–∫ —á–∏—Å–µ–ª.

Python 3 —É–¥–∞–ª–∏–ª —Ñ—É–Ω–∫—Ü–∏—é xrange () –≤ –ø–æ–ª—å–∑—É –Ω–æ–≤–∞—è —Ñ—É–Ω–∫—Ü–∏—è —Å –∏–º–µ–Ω–µ–º range () . –§—É–Ω–∫—Ü–∏—è range (), –∫–∞–∫ –∏ xrange (), —Å–æ–∑–¥–∞–µ—Ç –¥–∏–∞–ø–∞–∑–æ–Ω —á–∏—Å–µ–ª.

–ú–µ–∂–¥—É xrange –µ—Å—Ç—å –¥–≤–∞ —Ä–∞–∑–ª–∏—á–∏—è. () –∏ range ();

  • xrange () –∏ range () –∏–º–µ—é—Ç —Ä–∞–∑–Ω—ã–µ –∏–º–µ–Ω–∞.
  • –§—É–Ω–∫—Ü–∏—è xrange () –≥–µ–Ω–µ—Ä–∏—Ä—É–µ—Ç —Å–ø–∏—Å–æ–∫ —á–∏—Å–µ–ª. –§—É–Ω–∫—Ü–∏—è range () –≥–µ–Ω–µ—Ä–∏—Ä—É–µ—Ç –æ–±—ä–µ–∫—Ç.

–ü–æ—Å–∫–æ–ª—å–∫—É —Ñ—É–Ω–∫—Ü–∏—è range () –≥–µ–Ω–µ—Ä–∏—Ä—É–µ—Ç –æ–±—ä–µ–∫—Ç, –≤—ã –¥–æ–ª–∂–Ω—ã –ø—Ä–µ–æ–±—Ä–∞–∑–æ–≤–∞—Ç—å –µ–≥–æ –≤ —Å–ø–∏—Å–æ–∫, –µ—Å–ª–∏ –≤—ã —Ö–æ—Ç–∏—Ç–µ –ø—Ä–æ—Å–º–æ—Ç—Ä–µ—Ç—å —Å–ø–∏—Å–æ–∫ –Ω–æ–º–µ—Ä–æ–≤. –í –æ—Å—Ç–∞–ª—å–Ω–æ–º —ç—Ç–∏ –¥–≤–∞ –º–µ—Ç–æ–¥–∞ —Ä–∞–±–æ—Ç–∞—é—Ç –æ–¥–∏–Ω–∞–∫–æ–≤–æ.

–ü—Ä–∏–º–µ—Ä —Å—Ü–µ–Ω–∞—Ä–∏—è

–ú—ã —Å–æ–±–∏—Ä–∞–µ–º—Å—è –Ω–∞–ø–∏—Å–∞—Ç—å –ø—Ä–æ–≥—Ä–∞–º–º—É, –∫–æ—Ç–æ—Ä–∞—è –æ—Ç–æ–±—Ä–∞–∂–∞–µ—Ç –ø–µ—Ä–≤—ã—Ö –Ω–µ—Å–∫–æ–ª—å–∫–∏—Ö –∏–≥—Ä–æ–∫–æ–≤, –Ω–∞—Ö–æ–¥—è—â–∏—Ö—Å—è –≤ –≤–µ—Ä—Ö–Ω–µ–π —á–∞—Å—Ç–∏ –∫–∞—Ä—Ç—ã. —Ç–∞–±–ª–∏—Ü–∞ –ª–∏–¥–µ—Ä–æ–≤ –∏–≥—Ä—ã. –î–ª—è –Ω–∞—á–∞–ª–∞ –ø–æ–∑–≤–æ–ª—å—Ç–µ " s –æ–±—ä—è–≤–∏—Ç—å –Ω–∞—à—É —Ç–∞–±–ª–∏—Ü—É –ª–∏–¥–µ—Ä–æ–≤ –≤ –≤–∏–¥–µ —Å–ø–∏—Å–∫–∞ :

81% —É—á–∞—Å—Ç–Ω–∏–∫–æ–≤ –∑–∞—è–≤–∏–ª–∏, —á—Ç–æ –ø–æ—Å–ª–µ –±—É—Ç–∫–µ–º–ø–∞ –æ–Ω–∏ –ø–æ—á—É–≤—Å—Ç–≤–æ–≤–∞–ª–∏ —Å–µ–±—è –±–æ–ª–µ–µ —É–≤–µ—Ä–µ–Ω–Ω—ã–º–∏ –≤ —Å–≤–æ–∏—Ö –ø–µ—Ä—Å–ø–µ–∫—Ç–∏–≤–∞—Ö —Ç—Ä—É–¥–æ—É—Å—Ç—Ä–æ–π—Å—Ç–≤–∞ –≤ —Å—Ñ–µ—Ä–µ –≤—ã—Å–æ–∫–∏—Ö —Ç–µ—Ö–Ω–æ–ª–æ–≥–∏–π. –ü–æ–ª—É—á–∏—Ç–µ –ø—Ä–∏–≥–ª–∞—à–µ–Ω–∏–µ –Ω–∞ —É—á–µ–±–Ω—ã–π –∫—É—Ä—Å —Å–µ–≥–æ–¥–Ω—è.

–°—Ä–µ–¥–Ω–∏–π –≤—ã–ø—É—Å–∫–Ω–∏–∫ —É—á–µ–±–Ω–æ–≥–æ –∫—É—Ä—Å–∞ –ø–æ—Ç—Ä–∞—Ç–∏–ª –º–µ–Ω–µ–µ —à–µ—Å—Ç–∏ –º–µ—Å—è—Ü–µ–≤ –Ω–∞ –ø–µ—Ä–µ—Ö–æ–¥–Ω—É—é –∫–∞—Ä—å–µ—Ä—É, –æ—Ç –Ω–∞—á–∞–ª–∞ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –¥–æ –ø–æ–∏—Å–∫–∞ —Å–≤–æ–µ–π –ø–µ—Ä–≤–æ–π —Ä–∞–±–æ—Ç—ã.

–î–∞–ª–µ–µ –º—ã –∏–¥–µ–º. —á—Ç–æ–±—ã —Å–ø—Ä–æ—Å–∏—Ç—å –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª—è, —Å–∫–æ–ª—å–∫–æ –æ—á–∫–æ–≤ –æ–Ω —Ö–æ—Ç–µ–ª –±—ã –ø—Ä–æ—Å–º–æ—Ç—Ä–µ—Ç—å:

–ú—ã –∫–æ–Ω–≤–µ—Ä—Ç–∏—Ä—É–µ–º –∑–Ω–∞—á–µ–Ω–∏–µ, –∫–æ—Ç–æ—Ä–æ–µ –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª—å –≤—Å—Ç–∞–≤–ª—è–µ—Ç, –≤ —Ü–µ–ª–æ–µ —á–∏—Å–ª–æ. –≠—Ç–æ —Å–≤—è–∑–∞–Ω–æ —Å —Ç–µ–º, —á—Ç–æ —Ñ—É–Ω–∫—Ü–∏—è xrange () –ø–æ–¥–¥–µ—Ä–∂–∏–≤–∞–µ—Ç —Ç–æ–ª—å–∫–æ —Ü–µ–ª—ã–µ —á–∏—Å–ª–∞.

–ó–∞—Ç–µ–º –ø–æ–∑–≤–æ–ª—å—Ç–µ " –ø—Ä–æ–π—Ç–∏ –ø–æ –Ω–∞—à–µ–º—É —Å–ø–∏—Å–∫—É –ª–∏–¥–µ—Ä–æ–≤, –∏—Å–ø–æ–ª—å–∑—É—è —Ü–∏–∫–ª for . –ú—ã –±—É–¥–µ–º –æ—Ç–æ–±—Ä–∞–∂–∞—Ç—å —Ç–æ–ª—å–∫–æ –∫–æ–ª–∏—á–µ—Å—Ç–≤–æ —Ä–µ–∑—É–ª—å—Ç–∞—Ç—ã, –∫–æ—Ç–æ—Ä—ã–µ –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª—å –∑–∞–ø—Ä–æ—Å–∏–ª –ø—Ä–æ—Å–º–æ—Ç—Ä–µ—Ç—å –Ω–∞ –∫–æ–Ω—Å–æ–ª–∏:

–ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º —Ñ—É–Ω–∫—Ü–∏—é xrange () –¥–ª—è –≥–µ–Ω–µ—Ä–∞—Ü–∏–∏ –¥–∏–∞–ø–∞–∑–æ–Ω–∞ —á–∏—Å–µ–ª –æ—Ç 0 –¥–æ —á–∏—Å–ª–∞ –≤—Å—Ç–∞–≤–ª–µ–Ω–Ω—ã–π –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª–µ–º. –í –Ω–∞—à–µ–º —Ü–∏–∫–ª–µ for –º—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –æ–ø–µ—Ä–∞—Ç–æ—Ä print () –¥–ª—è –≤—ã–≤–æ–¥–∞ –∑–∞–ø–∏—Å–∏ —Ç–∞–±–ª–∏—Ü—ã –ª–∏–¥–µ—Ä–æ–≤, –∫–æ—Ç–æ—Ä–∞—è –∫–æ—Ä—Ä–µ–ª–∏—Ä—É–µ—Ç —Å —á–∏—Å–ª–æ–º –≤ —Å–ø–∏—Å–∫–µ xrange (), –∫–æ—Ç–æ—Ä–æ–µ –Ω–∞—à —Ü–∏–∫–ª –ø—Ä–æ—Å–º–∞—Ç—Ä–∏–≤–∞–µ—Ç.

–ú—ã –ø–µ—á–∞—Ç–∞–µ–º –∑–Ω–∞—á–µ–Ω–∏–µ " l " –ø–ª—é—Å –æ–¥–∏–Ω —Ä—è–¥–æ–º —Å –∏–º–µ–Ω–µ–º –∏–≥—Ä–æ–∫–∞. –≠—Ç–æ –ø–æ–∑–≤–æ–ª—è–µ—Ç –Ω–∞–º —É–≤–∏–¥–µ—Ç—å –∏—Ö –ø–æ–∑–∏—Ü–∏—é. –ü–æ—Ç–æ–º—É —á—Ç–æ —Å–ø–∏—Å–∫–∏ –Ω–∞—Ö–æ–¥—è—Ç—Å—è –≤ dexed —Å –Ω—É–ª—è , –º—ã –¥–æ–±–∞–≤–ª—è–µ–º –µ–¥–∏–Ω–∏—Ü—É –∫ " l & rdquo ;. –≠—Ç–æ –ø—Ä–µ–¥–æ—Ç–≤—Ä–∞—â–∞–µ—Ç –ø–æ–ø–∞–¥–∞–Ω–∏–µ –ø–µ—Ä–≤–æ–≥–æ –∏–≥—Ä–æ–∫–∞ –≤ –Ω–∞—à–µ–º —Å–ø–∏—Å–∫–µ –Ω–∞ –ø–æ–∑–∏—Ü–∏—é " 0 " –∏ —Ç–∞–∫ –¥–∞–ª–µ–µ.

–î–∞–≤–∞–π—Ç–µ –∑–∞–ø—É—Å—Ç–∏–º –Ω–∞—à –∫–æ–¥ –∏ –ø–æ—Å–º–æ—Ç—Ä–∏–º, —á—Ç–æ –ø—Ä–æ–∏–∑–æ–π–¥–µ—Ç:

–ù–∞—à–∞ –ø—Ä–æ–≥—Ä–∞–º–º–∞ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –æ—à–∏–±–∫—É.

–ú—ã –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–ª–∏ xrange () –¥–ª—è —Å–æ–∑–¥–∞–Ω–∏—è –¥–∏–∞–ø–∞–∑–æ–Ω–∞ —á–∏—Å–µ–ª. –í Python 2 —ç—Ç–æ –±—ã–ª–æ –±—ã –ø—Ä–∞–≤–∏–ª—å–Ω–æ. –ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º Python 3 –¥–ª—è –∑–∞–ø—É—Å–∫–∞ –Ω–∞—à–µ–π –ø—Ä–æ–≥—Ä–∞–º–º—ã, —á—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –º—ã –Ω–µ –º–æ–∂–µ–º —Å—Å—ã–ª–∞—Ç—å—Å—è –Ω–∞ —Ñ—É–Ω–∫—Ü–∏—é xrange ().

–ß—Ç–æ–±—ã —Ä–µ—à–∏—Ç—å –Ω–∞—à—É –æ—à–∏–±–∫—É, –Ω–∞–º –Ω—É–∂–Ω–æ –∑–∞–º–µ–Ω–∏—Ç—å xrange () —Å –ø–æ–º–æ—â—å—é –º–µ—Ç–æ–¥–∞ range ():

–î–ª—è —ç—Ç–æ–≥–æ –≤–∞—Ä–∏–∞–Ω—Ç–∞ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏—è –æ–±–∞ xrange () –∏ range () –≤–µ—Ä–Ω–µ—Ç —Ç–æ—Ç –∂–µ —Ä–µ–∑—É–ª—å—Ç–∞—Ç. –î–∞–≤–∞–π—Ç–µ –∑–∞–ø—É—Å—Ç–∏–º –Ω–∞—à –∫–æ–¥ –∏ –ø–æ—Å–º–æ—Ç—Ä–∏–º, —Ä–∞–±–æ—Ç–∞–µ—Ç –ª–∏ –æ–Ω:

–ù–∞—à–∞ –ø—Ä–æ–≥—Ä–∞–º–º–∞ —É—Å–ø–µ—à–Ω–æ –æ—Ç–æ–±—Ä–∞–∂–∞–µ—Ç –∏–º–µ–Ω–∞ –∏–≥—Ä–æ–∫–æ–≤ –≤ —Ç—É—Ä–Ω–∏—Ä–µ, –∫–æ—Ç–æ—Ä—ã–µ –∑–∞–Ω–∏–º–∞—é—Ç –ø–µ—Ä–≤—ã–µ –¥–≤–µ –ø–æ–∑–∏—Ü–∏–∏ –≤ —Ç–∞–±–ª–∏—Ü–µ –ª–∏–¥–µ—Ä–æ–≤.

–ü–µ—Ä–µ–æ–ø—Ä–µ–¥–µ–ª–µ–Ω–∏–µ –º–µ—Ç–æ–¥–∞ xrange ()

–ü–æ—Ç–µ–Ω—Ü–∏–∞–ª—å–Ω—ã–º —Ä–µ—à–µ–Ω–∏–µ–º —ç—Ç–æ–π –ø—Ä–æ–±–ª–µ–º—ã —è–≤–ª—è–µ—Ç—Å—è –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–∏–µ –ø–µ—Ä–µ–º–µ–Ω–Ω–æ–π —Å –∏–º–µ–Ω–µ–º xrange –≤ –Ω–∞—á–∞–ª–µ –≤–∞—à–µ–π –ø—Ä–æ–≥—Ä–∞–º–º—ã, –∫–æ—Ç–æ—Ä–∞—è —Å–æ–≤–ø–∞–¥–∞–µ—Ç —Å —Ñ—É–Ω–∫—Ü–∏–µ–π range ():

–≠—Ç–æ –Ω–µ –ª—É—á—à–µ–µ —Ä–µ—à–µ–Ω–∏–µ —ç—Ç–æ–π –æ—à–∏–±–∫–∏. –≠—Ç–æ —Å–≤—è–∑–∞–Ω–æ —Å —Ç–µ–º, —á—Ç–æ –≤—ã –ø—Ä–æ—Å—Ç–æ –∏–∑–±–µ–≥–∞–µ—Ç–µ –ø—Ä–æ–±–ª–µ–º—ã –ø–µ—Ä–µ–∏–º–µ–Ω–æ–≤–∞–Ω–∏—è —Å—É—â–µ—Å—Ç–≤—É—é—â–∏—Ö –º–µ—Ç–æ–¥–æ–≤. –ö—Ç–æ-—Ç–æ –º–æ–≥ –±—ã –∑–∞–ø—É—Ç–∞—Ç—å—Å—è, –ø—Ä–æ—á–∏—Ç–∞–≤ –±–∞–∑—É –∫–æ–¥–∞ Python 3 –∏ —É–≤–∏–¥–µ–≤ –û–ø–µ—Ä–∞—Ç–æ—Ä—ã xrange (), –¥–∞–∂–µ –µ—Å–ª–∏ –≤—ã –æ–ø—Ä–µ–¥–µ–ª–∏–ª–∏ xrange –∫–∞–∫ –ø–µ—Ä–µ–º–µ–Ω–Ω—É—é.

–õ—É—á—à–µ–µ —Ä–µ—à–µ–Ω–∏–µ - –ø–µ—Ä–µ–∏–º–µ–Ω–æ–≤–∞—Ç—å –æ–ø–µ—Ä–∞—Ç–æ—Ä—ã xrange () –≤ range () –∏ –≤–Ω–µ—Å—Ç–∏ –Ω–µ–æ–±—Ö–æ–¥–∏–º—ã–µ –∏–∑–º–µ–Ω–µ–Ω–∏—è, —á—Ç–æ–±—ã –≤–∞—à–∞ –∫–æ–¥–æ–≤–∞—è –±–∞–∑–∞ —Ä–∞–±–æ—Ç–∞–ª–∞ –≤ Python 3.

–ó–∞–∫–ª—é—á–µ–Ω–∏–µ

–û—à–∏–±–∫–∞ " NameError: name " xra nge " –Ω–µ –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–æ " –æ—à–∏–±–∫–∞ –≤–æ–∑–Ω–∏–∫–∞–µ—Ç, –∫–æ–≥–¥–∞ –≤—ã –ø—ã—Ç–∞–µ—Ç–µ—Å—å –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –º–µ—Ç–æ–¥ xrange () –¥–ª—è —Å–æ–∑–¥–∞–Ω–∏—è –¥–∏–∞–ø–∞–∑–æ–Ω–∞ —á–∏—Å–µ–ª –≤ Python 3. –ß—Ç–æ–±—ã —É—Å—Ç—Ä–∞–Ω–∏—Ç—å —ç—Ç—É –æ—à–∏–±–∫—É, –æ–±–Ω–æ–≤–∏—Ç–µ —Å–≤–æ–π –∫–æ–¥, —á—Ç–æ–±—ã –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å range (), –ø–æ—Å—Ç–∞–≤–ª—è–µ–º—ã–π —Å Python 3.

range () - —ç—Ç–æ Python 3, –∑–∞–º–µ–Ω—è—é—â–∏–π xrange (). –¢–µ–ø–µ—Ä—å —É –≤–∞—Å –µ—Å—Ç—å –Ω–æ—É-—Ö–∞—É, –Ω–µ–æ–±—Ö–æ–¥–∏–º–æ–µ –¥–ª—è —Ä–µ—à–µ–Ω–∏—è —ç—Ç–æ–π –æ—à–∏–±–∫–∏ –∫–∞–∫ –ø—Ä–æ—Ñ–µ—Å—Å–∏–æ–Ω–∞–ª!

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method